From f9a4d595985cf7db631986a3aec489e02073d9c6 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Wed, 1 Jan 2025 16:31:28 +1300 Subject: [PATCH] Garmin: Remove File Name from File Data. Remove the file name from the beginning of the file data buffer. This is in preparation to a move to shift the .FIT file importer to 'Import log files'. The file name in the buffer does not seem to be used for anything, and it seems to be wrong to have this added only for the parser to then have to remove this non-file-content again first thing. Fingerprinting has been confirmed as working after this change. Signed-off-by: Michael Keller --- src/garmin.c | 1 - src/garmin_parser.c | 27 +++++++++++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/garmin.c b/src/garmin.c index 16c74640..43161039 100644 --- a/src/garmin.c +++ b/src/garmin.c @@ -558,7 +558,6 @@ garmin_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void // Reset the membuffer, read the data dc_buffer_clear(file); - dc_buffer_append(file, name, FIT_NAME_SIZE); #ifdef HAVE_LIBMTP if (device->use_mtp) status = mtp_read_file(device, files.array[i].mtp_id, file); diff --git a/src/garmin_parser.c b/src/garmin_parser.c index d28b5f26..ba97315a 100644 --- a/src/garmin_parser.c +++ b/src/garmin_parser.c @@ -452,7 +452,7 @@ struct field_desc { { \ char fmtbuf[FMTSIZE]; \ if (strcmp(#type, base_type_info[base_type].type_name)) \ - fprintf(stderr, "%s: %s should be %s\n", #name, #type, base_type_info[base_type].type_name); \ + WARNING(g->base.context, "%s: %s should be %s\n", #name, #type, base_type_info[base_type].type_name); \ type val = type##_VALUE(g, p); \ if (val == type##_INVAL) return; \ type##_FORMAT(val, fmtbuf); \ @@ -1499,29 +1499,25 @@ traverse_data(struct garmin_parser_t *garmin) memset(&garmin->record_data, 0, sizeof(garmin->record_data)); memset(garmin->type_desc, 0, sizeof(garmin->type_desc)); - // The data starts with our filename fingerprint. Skip it. - if (len < FIT_NAME_SIZE) - return DC_STATUS_IO; - - DEBUG(garmin->base.context, "file %.*s", FIT_NAME_SIZE, data); - - data += FIT_NAME_SIZE; - len -= FIT_NAME_SIZE; - // The FIT header - if (len < 12) + if (len < 12) { + ERROR(garmin->base.context, " file too short for FIT header"); + return DC_STATUS_IO; + } hdrsize = data[0]; protocol = data[1]; profile = array_uint16_le(data+2); // these two fields are always little endian datasize = array_uint32_le(data+4); if (memcmp(data+8, ".FIT", 4)) { - DEBUG(garmin->base.context, " missing .FIT marker"); + ERROR(garmin->base.context, " missing .FIT marker"); + return DC_STATUS_IO; } if (hdrsize < 12 || datasize > len || datasize + hdrsize + 2 > len) { - DEBUG(garmin->base.context, " inconsistent size information hdrsize %d datasize %d len %d", hdrsize, datasize, len); + ERROR(garmin->base.context, " inconsistent size information hdrsize %d datasize %d len %d", hdrsize, datasize, len); + return DC_STATUS_IO; } garmin->dive.protocol = protocol; @@ -1563,8 +1559,11 @@ traverse_data(struct garmin_parser_t *garmin) DEBUG(garmin->base.context, "Regular record for type %d", record); len = traverse_regular(garmin, data, datasize, record, &time); } - if (len <= 0 || len > datasize) + if (len <= 0 || len > datasize) { + ERROR(garmin->base.context, " traverse failed"); + return DC_STATUS_IO; + } data += len; datasize -= len;