From 89ae8b94cfb10e44d04bad37a0db2cbbae8bf8c0 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 27 Oct 2022 22:02:21 +0200 Subject: [PATCH] Fix the detection of empty dive profiles Not only the two byte end-of-profile marker 0xFDFD is a valid empty dive profile, but also a profile with the length field present and set to 8 bytes. In that case the actual length will be just 5 bytes. --- src/hw_ostc3.c | 2 +- src/hw_ostc_parser.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c index cfb25d7..7b87587 100644 --- a/src/hw_ostc3.c +++ b/src/hw_ostc3.c @@ -869,7 +869,7 @@ hw_ostc3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, voi } else if (length == RB_LOGBOOK_SIZE_FULL + 2) { // A profile containing only the 2 byte end-of-profile // marker is considered a valid empty profile. - } else if (length < RB_LOGBOOK_SIZE_FULL + 5 + 2 || + } else if (length < RB_LOGBOOK_SIZE_FULL + 5 || array_uint24_le (profile + RB_LOGBOOK_SIZE_FULL) + delta != array_uint24_le (profile + HDR_FULL_LENGTH)) { // If there is more data available, then there should be a // valid profile header containing a length matching the diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index 90994f8..d745ef8 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -20,6 +20,7 @@ */ #include +#include #include "libdivecomputer/units.h" @@ -679,8 +680,10 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call const hw_ostc_layout_t *layout = parser->layout; // Exit if no profile data available. - if (size == header || (size == header + 2 && - data[header] == 0xFD && data[header + 1] == 0xFD)) { + const unsigned char empty[] = {0x08, 0x00, 0x00, 0xFD, 0xFD}; + if (size == header || + (size == header + 2 && memcmp(data + header, empty + 3, 2) == 0) || + (size == header + 5 && memcmp(data + header, empty, 5) == 0)) { parser->cached = PROFILE; return DC_STATUS_SUCCESS; }