Added some comment about the overflow protection

This commit is contained in:
Pünkösd Marcell 2020-11-08 23:48:10 +01:00
parent 4fb5301423
commit f38dcfe4f1

View File

@ -152,9 +152,11 @@ uint8_t validate_caff_file(uint8_t *data, uint64_t data_len) {
frame_counter++; frame_counter++;
uint64_t seek_by = frame_header->length + sizeof(caff_frame_header_t); uint64_t seek_by = frame_header->length + sizeof(caff_frame_header_t);
if (seek_by > len_remaining) { if (seek_by > len_remaining) {
// Since we working with unsigned integers, this check here is explicitly needed
// So that the following subtraction won't cause integer overflow
return CAFF_PARSE_LENGTH_ERROR; return CAFF_PARSE_LENGTH_ERROR;
} }
len_remaining -= seek_by; len_remaining -= seek_by; // Overflow here is protected by the check above
p += seek_by; p += seek_by;
} }