From 39d44b5e6028d90067d5d09413522b84ab319468 Mon Sep 17 00:00:00 2001 From: Wan-Teh Chang Date: Wed, 1 May 2024 15:04:33 -0700 Subject: [PATCH 1/2] Further cleanup in avifParseSampleDescriptionBox() Rename the `remainingBytes` variable as `sampleEntryBytes`. The `remainingBytes` name made sense when the variable stored the return value of avifROStreamRemainingBytes(&s). The variable now stores the value of sampleEntryHeader.size, so the name `sampleEntryBytes` is more appropriate. Remove an extraneous pair of parentheses around a conditional expression. Replace an instance of sampleEntryHeader.size with `sampleEntryBytes`. --- src/read.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/read.c b/src/read.c index 7d23766dd5..a7878be6e9 100644 --- a/src/read.c +++ b/src/read.c @@ -3259,20 +3259,20 @@ static avifResult avifParseSampleDescriptionBox(avifSampleTable * sampleTable, return AVIF_RESULT_OUT_OF_MEMORY; } memcpy(description->format, sampleEntryHeader.type, sizeof(description->format)); - size_t remainingBytes = sampleEntryHeader.size; - if ((avifGetCodecType(description->format) != AVIF_CODEC_TYPE_UNKNOWN)) { - if (remainingBytes < VISUALSAMPLEENTRY_SIZE) { + size_t sampleEntryBytes = sampleEntryHeader.size; + if (avifGetCodecType(description->format) != AVIF_CODEC_TYPE_UNKNOWN) { + if (sampleEntryBytes < 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, - remainingBytes - VISUALSAMPLEENTRY_SIZE, + sampleEntryBytes - VISUALSAMPLEENTRY_SIZE, diag)); } - AVIF_CHECKERR(avifROStreamSkip(&s, sampleEntryHeader.size), AVIF_RESULT_BMFF_PARSE_FAILED); + AVIF_CHECKERR(avifROStreamSkip(&s, sampleEntryBytes), AVIF_RESULT_BMFF_PARSE_FAILED); } return AVIF_RESULT_OK; } From ed13de0540f240ae12889c76fd84bf271acf3a86 Mon Sep 17 00:00:00 2001 From: Wan-Teh Chang Date: Wed, 1 May 2024 15:46:03 -0700 Subject: [PATCH 2/2] Declare sampleEntryBytes as const --- src/read.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/read.c b/src/read.c index a7878be6e9..03f69b1e38 100644 --- a/src/read.c +++ b/src/read.c @@ -3259,7 +3259,7 @@ static avifResult avifParseSampleDescriptionBox(avifSampleTable * sampleTable, return AVIF_RESULT_OUT_OF_MEMORY; } memcpy(description->format, sampleEntryHeader.type, sizeof(description->format)); - size_t sampleEntryBytes = sampleEntryHeader.size; + const size_t sampleEntryBytes = sampleEntryHeader.size; if (avifGetCodecType(description->format) != AVIF_CODEC_TYPE_UNKNOWN) { if (sampleEntryBytes < VISUALSAMPLEENTRY_SIZE) { avifDiagnosticsPrintf(diag, "Not enough bytes to parse VisualSampleEntry");