Skip to content

Commit 32fa2b4

Browse files
committed
Detect overflows when adding numbers to offset
Detect overflows when adding numbers to `offset` in avifJPEGExtractGainMapImageFromMpf().
1 parent 7fa9306 commit 32fa2b4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

apps/shared/avifjpeg.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ static avifBool avifJPEGExtractGainMapImageFromMpf(FILE * f,
715715
for (int mpTagIdx = 0; mpTagIdx < mpTagCount; ++mpTagIdx) {
716716
uint16_t tagId;
717717
AVIF_CHECK(avifJPEGReadU16(segmentData, &tagId, &offset, isBigEndian));
718+
if (UINT32_MAX - offset < 2 + 4) {
719+
return AVIF_FALSE;
720+
}
718721
offset += 2; // Skip data format.
719722
offset += 4; // Skip num components.
720723
uint8_t valueBytes[4];
@@ -749,12 +752,18 @@ static avifBool avifJPEGExtractGainMapImageFromMpf(FILE * f,
749752
AVIF_CHECK(avifJPEGFindMpfSegmentOffset(f, &mpfSegmentOffset));
750753

751754
for (uint32_t imageIdx = 0; imageIdx < numImages; ++imageIdx) {
755+
if (UINT32_MAX - offset < 4) {
756+
return AVIF_FALSE;
757+
}
752758
offset += 4; // Skip "Individual Image Attribute"
753759
uint32_t imageSize;
754760
AVIF_CHECK(avifJPEGReadU32(segmentData, &imageSize, &offset, isBigEndian));
755761
uint32_t imageDataOffset;
756762
AVIF_CHECK(avifJPEGReadU32(segmentData, &imageDataOffset, &offset, isBigEndian));
757763

764+
if (UINT32_MAX - offset < 4) {
765+
return AVIF_FALSE;
766+
}
758767
offset += 4; // Skip "Dependent image Entry Number" (2 + 2 bytes)
759768
if (imageDataOffset == 0) {
760769
// 0 is a special value which indicates the first image.

0 commit comments

Comments
 (0)