Skip to content

Commit 657af9c

Browse files
committed
avifImageCopy: check avifImageCreateEmpty() result for gain map image
When the destination image has no gain map image yet but the source does, avifImageCopy() called avifImageCreateEmpty() and passed the result to a recursive avifImageCopy() without checking for allocation failure. Under out-of-memory conditions this dereferenced a NULL pointer in avifImageFreePlanes() at the start of the recursive call. Add the missing AVIF_CHECKERR, matching the existing pattern used for the avifGainMapCreate() allocation a few lines above.
1 parent 3c66271 commit 657af9c

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ The changes are relative to the previous release, unless the baseline is specifi
2323
* Update svt.cmd/svt.sh/LocalSvt.cmake: v4.1.0
2424
* Fix decoding layered image with multiple scaled alpha layers
2525
* Fix NaN bypass of AVIF_CLAMP in gain map tone mapping (use fminf/fmaxf)
26+
* Fix null pointer dereference in avifImageCopy() when avifImageCreateEmpty()
27+
fails to allocate the destination gain map image.
2628
* avifenc: reject mismatched --depth for Y4M input
2729
* Use libaom AOMD_SET_FRAME_SIZE_LIMIT if available
2830

src/avif.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ avifResult avifImageCopy(avifImage * dstImage, const avifImage * srcImage, avifP
305305
if (srcImage->gainMap->image) {
306306
if (!dstImage->gainMap->image) {
307307
dstImage->gainMap->image = avifImageCreateEmpty();
308+
AVIF_CHECKERR(dstImage->gainMap->image, AVIF_RESULT_OUT_OF_MEMORY);
308309
}
309310
AVIF_CHECKRES(avifImageCopy(dstImage->gainMap->image, srcImage->gainMap->image, planes));
310311
} else if (dstImage->gainMap->image) {

0 commit comments

Comments
 (0)