Skip to content

Commit

Permalink
APP14 read improvements
Browse files Browse the repository at this point in the history
- bound checking - length-2 must be used (2 not substracted from length
but *image ptr has been incremented by 2)
- unknown APP14 - print original len (with length) and in parenthesis
also the value substracted by 2 to be clear about the val meaning
  • Loading branch information
MartinPulec committed Oct 15, 2024
1 parent 4111270 commit 0652d1e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/gpujpeg_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ gpujpeg_reader_read_spiff_directory(uint8_t** image, const uint8_t* image_end, i
/**
* Read APP8 marker
*
* Obtains colorspace from APP14.
* Obtains colorspace from APP8.
*
* @param decoder decoder state
* @param[in,out] image JPEG data
Expand Down Expand Up @@ -547,7 +547,7 @@ gpujpeg_reader_read_app14(uint8_t** image, const uint8_t* image_end, enum gpujpe

int length = gpujpeg_reader_read_2byte(*image);

if(length > image_end - *image) {
if ( length - 2 > image_end - *image ) {
fprintf(stderr, "[GPUJPEG] [Error] APP14 segment goes beyond end of data\n");
return -1;
}
Expand All @@ -564,8 +564,8 @@ gpujpeg_reader_read_app14(uint8_t** image, const uint8_t* image_end, enum gpujpe
return rc;
}

fprintf(stderr, "[GPUJPEG] [Warning] Unknown APP14 marker %dB (%dB) long was presented: ", length, length - 2);
length -= 2;
fprintf(stderr, "[GPUJPEG] [Warning] Unknown APP14 marker %dB long was presented: ", length);
while (length > 0 && isprint(**image)) {
putc(*(*image)++, stderr);
length--;
Expand Down

0 comments on commit 0652d1e

Please sign in to comment.