Skip to content

Commit 1f8bd19

Browse files
committed
gainmap: check avifImageCreateEmpty() result
avifRGBImageApplyGainMap() calls avifImageCreateEmpty() to back the rescaledGainMap when the gain map image's dimensions differ from the base image's, but does not check the return value. The next line calls avifImageSetViewRect(rescaledGainMap, ...), which dereferences the destination image via avifImageFreePlanes() before any rect validation, so a NULL return from avifImageCreateEmpty() crashes the caller under memory pressure. This is the same pattern fixed for avifImageCopy() in PR AOMediaCodec#3201. Bail to the existing cleanup label with AVIF_RESULT_OUT_OF_MEMORY when the allocation fails.
1 parent 3c66271 commit 1f8bd19

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/gainmap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ avifResult avifRGBImageApplyGainMap(const avifRGBImage * baseImage,
187187

188188
if (gainMap->image->width != width || gainMap->image->height != height) {
189189
rescaledGainMap = avifImageCreateEmpty();
190+
if (rescaledGainMap == NULL) {
191+
res = AVIF_RESULT_OUT_OF_MEMORY;
192+
goto cleanup;
193+
}
190194
const avifCropRect rect = { 0, 0, gainMap->image->width, gainMap->image->height };
191195
res = avifImageSetViewRect(rescaledGainMap, gainMap->image, &rect);
192196
if (res != AVIF_RESULT_OK) {

0 commit comments

Comments
 (0)