Skip to content

Commit

Permalink
Garmin: Remove File Name from File Data.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mikeller committed Jan 1, 2025
1 parent a0684b8 commit f9a4d59
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/garmin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 13 additions & 14 deletions src/garmin_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit f9a4d59

Please sign in to comment.