Skip to content

Commit

Permalink
read.c: Use header size when parsing VisualSampleEntry
Browse files Browse the repository at this point in the history
The current code uses avifROStreamRemainingBytes which is not
correct. We are inside a for loop where each loop is a box with
a fixed header size. So within each loop, we should not parse
more than that loop's header size.

Also return an error if there aren't enough bytes to parse
VisualSampleEntry.
  • Loading branch information
vigneshvg committed Apr 30, 2024
1 parent ab86c0c commit 2be0ec9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -3259,8 +3259,12 @@ static avifResult avifParseSampleDescriptionBox(avifSampleTable * sampleTable,
return AVIF_RESULT_OUT_OF_MEMORY;
}
memcpy(description->format, sampleEntryHeader.type, sizeof(description->format));
size_t remainingBytes = avifROStreamRemainingBytes(&s);
if ((avifGetCodecType(description->format) != AVIF_CODEC_TYPE_UNKNOWN) && (remainingBytes > VISUALSAMPLEENTRY_SIZE)) {
size_t remainingBytes = sampleEntryHeader.size;
if ((avifGetCodecType(description->format) != AVIF_CODEC_TYPE_UNKNOWN)) {
if (remainingBytes < VISUALSAMPLEENTRY_SIZE) {
avifDiagnosticsPrintf(diag, "Not enough bytes to parse VisualSampleEntry");
return AVIF_RESULT_BMFF_PARSE_FAILED;
}
AVIF_CHECKRES(avifParseItemPropertyContainerBox(&description->properties,
rawOffset + avifROStreamOffset(&s) + VISUALSAMPLEENTRY_SIZE,
avifROStreamCurrent(&s) + VISUALSAMPLEENTRY_SIZE,
Expand Down

0 comments on commit 2be0ec9

Please sign in to comment.