Skip to content

Commit 043face

Browse files
jefdriesenmikeller
authored andcommitted
Verify the checksum in the dive header
The checksum can help to detect corrupt dives and/or bugs in the download code.
1 parent e141872 commit 043face

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/cressi_goa_parser.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "cressi_goa.h"
2525
#include "context-private.h"
2626
#include "parser-private.h"
27+
#include "checksum.h"
2728
#include "array.h"
2829

2930
#define ISINSTANCE(parser) dc_device_isinstance((parser), &cressi_goa_parser_vtable)
@@ -366,6 +367,13 @@ cressi_goa_init(cressi_goa_parser_t *parser)
366367
return DC_STATUS_DATAFORMAT;
367368
}
368369

370+
unsigned short crc = array_uint16_le (data + headersize + layout->headersize - 2);
371+
unsigned short ccrc = checksum_crc16_ccitt (data + headersize, layout->headersize - 2, 0xffff, 0x0000);
372+
if (crc != ccrc) {
373+
ERROR (abstract->context, "Unexpected header checksum (%04x %04x).", crc, ccrc);
374+
return DC_STATUS_DATAFORMAT;
375+
}
376+
369377
parser->layout = layout;
370378
parser->headersize = headersize;
371379
parser->divemode = divemode;

0 commit comments

Comments
 (0)