diff --git a/src/oceanic_common.c b/src/oceanic_common.c index 691e9a6..817e3e2 100644 --- a/src/oceanic_common.c +++ b/src/oceanic_common.c @@ -521,14 +521,13 @@ oceanic_common_device_profile (dc_device_t *abstract, dc_event_progress_t *progr // Remove padding from the profile. if (layout->highmem) { - unsigned char *profile = profiles + offset; - // profile+12 and the bottom 4 bits of profile+13 and the top 3 bits of profile+13 - // is the number of pages of profile data until the start of the footer - // (not including the prepended logbook entry). - unsigned int high_part = array_uint16_le (profile + 12) & 0xE000; - unsigned int low_part = array_uint16_le (profile + 12) & 0x0FFF; - unsigned int npages = ((high_part >> 1) | low_part) + 1; - // INFO (abstract->context, "profile npages: 0x%X (%d)", npages, npages); + // The logbook entry contains the total number of pages containing + // profile data, excluding the footer page. Limit the profile size + // to this size. + unsigned int value = array_uint16_le (profiles + offset + 12); + unsigned int value_hi = value & 0xE000; + unsigned int value_lo = value & 0x0FFF; + unsigned int npages = ((value_hi >> 1) | value_lo) + 1; unsigned int length = npages * PAGESIZE; if (rb_entry_size > length) { rb_entry_size = length;