Skip to content

Commit 1ce971e

Browse files
authored
Make avifImageAllocatePlanes() return avifResult
To catch memory allocation failures and invalid parameters, it is safer to return a status from avifImageAllocatePlanes() and from avifImageCopy(). Update CHANGELOG.md.
1 parent a6496dd commit 1ce971e

File tree

15 files changed

+314
-51
lines changed

15 files changed

+314
-51
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9-
There is an incompatible ABI change in this release. Members were removed from
10-
avifImage struct. It is necessary to recompile your code.
9+
There are incompatible ABI changes in this release. The alphaRange member was
10+
removed from avifImage struct. avifImageCopy() and avifImageAllocatePlanes()
11+
signatures changed. It is necessary to recompile your code. Also check the
12+
return values of avifImageCopy() and avifImageAllocatePlanes().
1113

1214
### Changed
1315
* Update aom.cmd: v3.4.0
1416
* Update svt.cmd/svt.sh: v1.1.0
17+
* avifImageCopy() and avifImageAllocatePlanes() now return avifResult instead of
18+
void to report invalid parameters or memory allocation failures
1519

1620
### Removed
1721
* alphaRange field was removed from the avifImage struct. It it presumed that

apps/avifenc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,11 @@ static avifBool avifImageSplitGrid(const avifImage * gridSplitImage, uint32_t gr
352352
avifImage * cellImage = avifImageCreateEmpty();
353353
gridCells[gridIndex] = cellImage;
354354

355-
avifImageCopy(cellImage, gridSplitImage, 0);
355+
const avifResult copyResult = avifImageCopy(cellImage, gridSplitImage, 0);
356+
if (copyResult != AVIF_RESULT_OK) {
357+
fprintf(stderr, "ERROR: Image copy failed: %s\n", avifResultToString(copyResult));
358+
return AVIF_FALSE;
359+
}
356360
cellImage->width = cellWidth;
357361
cellImage->height = cellHeight;
358362

apps/shared/avifjpeg.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void my_error_exit(j_common_ptr cinfo)
4040

4141
// An internal function used by avifJPEGReadCopy(), this is the shared libjpeg decompression code
4242
// for all paths avifJPEGReadCopy() takes.
43-
static void avifJPEGCopyPixels(avifImage * avif, struct jpeg_decompress_struct * cinfo)
43+
static avifBool avifJPEGCopyPixels(avifImage * avif, struct jpeg_decompress_struct * cinfo)
4444
{
4545
cinfo->raw_data_out = TRUE;
4646
jpeg_start_decompress(cinfo);
@@ -68,7 +68,9 @@ static void avifJPEGCopyPixels(avifImage * avif, struct jpeg_decompress_struct *
6868
readLines = AVIF_MAX(readLines, linesPerCall[i]);
6969
}
7070

71-
avifImageAllocatePlanes(avif, AVIF_PLANES_YUV);
71+
if (avifImageAllocatePlanes(avif, AVIF_PLANES_YUV) != AVIF_RESULT_OK) {
72+
return AVIF_FALSE;
73+
}
7274

7375
// destination avif channel for each jpeg channel
7476
avifChannelIndex targetChannel[3] = { AVIF_CHAN_Y, AVIF_CHAN_Y, AVIF_CHAN_Y };
@@ -102,6 +104,7 @@ static void avifJPEGCopyPixels(avifImage * avif, struct jpeg_decompress_struct *
102104
alreadyRead[i] += linesPerCall[i];
103105
}
104106
}
107+
return AVIF_TRUE;
105108
}
106109

107110
static avifBool avifJPEGHasCompatibleMatrixCoefficients(avifMatrixCoefficients matrixCoefficients)
@@ -148,19 +151,15 @@ static avifBool avifJPEGReadCopy(avifImage * avif, struct jpeg_decompress_struct
148151
}
149152
if (avif->yuvFormat == jpegFormat) {
150153
cinfo->out_color_space = JCS_YCbCr;
151-
avifJPEGCopyPixels(avif, cinfo);
152-
153-
return AVIF_TRUE;
154+
return avifJPEGCopyPixels(avif, cinfo);
154155
}
155156
}
156157

157158
// YUV->Grayscale: subsample Y plane not allowed.
158159
if ((avif->yuvFormat == AVIF_PIXEL_FORMAT_YUV400) && (cinfo->comp_info[0].h_samp_factor == cinfo->max_h_samp_factor &&
159160
cinfo->comp_info[0].v_samp_factor == cinfo->max_v_samp_factor)) {
160161
cinfo->out_color_space = JCS_YCbCr;
161-
avifJPEGCopyPixels(avif, cinfo);
162-
163-
return AVIF_TRUE;
162+
return avifJPEGCopyPixels(avif, cinfo);
164163
}
165164
}
166165
} else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
@@ -173,16 +172,16 @@ static avifBool avifJPEGReadCopy(avifImage * avif, struct jpeg_decompress_struct
173172
if ((avif->yuvFormat == AVIF_PIXEL_FORMAT_YUV400) || (avif->yuvFormat == AVIF_PIXEL_FORMAT_NONE)) {
174173
avif->yuvFormat = AVIF_PIXEL_FORMAT_YUV400;
175174
cinfo->out_color_space = JCS_GRAYSCALE;
176-
avifJPEGCopyPixels(avif, cinfo);
177-
178-
return AVIF_TRUE;
175+
return avifJPEGCopyPixels(avif, cinfo);
179176
}
180177

181178
// Grayscale->YUV: copy Y, fill UV with monochrome value.
182179
if ((avif->yuvFormat == AVIF_PIXEL_FORMAT_YUV444) || (avif->yuvFormat == AVIF_PIXEL_FORMAT_YUV422) ||
183180
(avif->yuvFormat == AVIF_PIXEL_FORMAT_YUV420)) {
184181
cinfo->out_color_space = JCS_GRAYSCALE;
185-
avifJPEGCopyPixels(avif, cinfo);
182+
if (!avifJPEGCopyPixels(avif, cinfo)) {
183+
return AVIF_FALSE;
184+
}
186185

187186
avifPixelFormatInfo info;
188187
avifGetPixelFormatInfo(avif->yuvFormat, &info);
@@ -199,7 +198,9 @@ static avifBool avifJPEGReadCopy(avifImage * avif, struct jpeg_decompress_struct
199198
((avif->yuvFormat == AVIF_PIXEL_FORMAT_YUV444) || (avif->yuvFormat == AVIF_PIXEL_FORMAT_NONE))) {
200199
avif->yuvFormat = AVIF_PIXEL_FORMAT_YUV444;
201200
cinfo->out_color_space = JCS_GRAYSCALE;
202-
avifJPEGCopyPixels(avif, cinfo);
201+
if (!avifJPEGCopyPixels(avif, cinfo)) {
202+
return AVIF_FALSE;
203+
}
203204

204205
memcpy(avif->yuvPlanes[AVIF_CHAN_U], avif->yuvPlanes[AVIF_CHAN_Y], (size_t)avif->yuvRowBytes[AVIF_CHAN_U] * avif->height);
205206
memcpy(avif->yuvPlanes[AVIF_CHAN_V], avif->yuvPlanes[AVIF_CHAN_Y], (size_t)avif->yuvRowBytes[AVIF_CHAN_V] * avif->height);
@@ -216,9 +217,7 @@ static avifBool avifJPEGReadCopy(avifImage * avif, struct jpeg_decompress_struct
216217
cinfo->comp_info[2].h_samp_factor == 1 && cinfo->comp_info[2].v_samp_factor == 1)) {
217218
avif->yuvFormat = AVIF_PIXEL_FORMAT_YUV444;
218219
cinfo->out_color_space = JCS_RGB;
219-
avifJPEGCopyPixels(avif, cinfo);
220-
221-
return AVIF_TRUE;
220+
return avifJPEGCopyPixels(avif, cinfo);
222221
}
223222
}
224223

apps/shared/y4m.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,16 +348,17 @@ avifBool y4mRead(const char * inputFilename, avifImage * avif, avifAppSourceTimi
348348
*sourceTiming = frame.sourceTiming;
349349
}
350350

351-
avifImageFreePlanes(avif, AVIF_PLANES_YUV | AVIF_PLANES_A);
351+
avifImageFreePlanes(avif, AVIF_PLANES_ALL);
352352
avif->width = frame.width;
353353
avif->height = frame.height;
354354
avif->depth = frame.depth;
355355
avif->yuvFormat = frame.format;
356356
avif->yuvRange = frame.range;
357357
avif->yuvChromaSamplePosition = frame.chromaSamplePosition;
358-
avifImageAllocatePlanes(avif, AVIF_PLANES_YUV);
359-
if (frame.hasAlpha) {
360-
avifImageAllocatePlanes(avif, AVIF_PLANES_A);
358+
avifResult allocationResult = avifImageAllocatePlanes(avif, frame.hasAlpha ? AVIF_PLANES_ALL : AVIF_PLANES_YUV);
359+
if (allocationResult != AVIF_RESULT_OK) {
360+
fprintf(stderr, "Failed to allocate the planes: %s\n", avifResultToString(allocationResult));
361+
goto cleanup;
361362
}
362363

363364
avifPixelFormatInfo formatInfo;

examples/avif_example_encode.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ int main(int argc, char * argv[])
4141
// If you have YUV(A) data you want to encode, use this path
4242
printf("Encoding raw YUVA data\n");
4343

44-
avifImageAllocatePlanes(image, AVIF_PLANES_YUV | AVIF_PLANES_A);
44+
const avifResult allocateResult = avifImageAllocatePlanes(image, AVIF_PLANES_ALL);
45+
if (allocateResult != AVIF_RESULT_OK) {
46+
fprintf(stderr, "Failed to allocate the planes: %s\n", avifResultToString(allocateResult));
47+
goto cleanup;
48+
}
4549

4650
// Fill your YUV(A) data here
4751
memset(image->yuvPlanes[AVIF_CHAN_Y], 255, image->yuvRowBytes[AVIF_CHAN_Y] * image->height);

include/avif/avif.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ typedef struct avifImage
466466

467467
AVIF_API avifImage * avifImageCreate(int width, int height, int depth, avifPixelFormat yuvFormat);
468468
AVIF_API avifImage * avifImageCreateEmpty(void); // helper for making an image to decode into
469-
AVIF_API void avifImageCopy(avifImage * dstImage, const avifImage * srcImage, avifPlanesFlags planes); // deep copy
469+
AVIF_API avifResult avifImageCopy(avifImage * dstImage, const avifImage * srcImage, avifPlanesFlags planes); // deep copy
470470
AVIF_API avifResult avifImageSetViewRect(avifImage * dstImage, const avifImage * srcImage, const avifCropRect * rect); // shallow copy, no metadata
471471
AVIF_API void avifImageDestroy(avifImage * image);
472472

@@ -476,8 +476,8 @@ AVIF_API void avifImageSetProfileICC(avifImage * image, const uint8_t * icc, siz
476476
AVIF_API void avifImageSetMetadataExif(avifImage * image, const uint8_t * exif, size_t exifSize);
477477
AVIF_API void avifImageSetMetadataXMP(avifImage * image, const uint8_t * xmp, size_t xmpSize);
478478

479-
AVIF_API void avifImageAllocatePlanes(avifImage * image, avifPlanesFlags planes); // Ignores any pre-existing planes
480-
AVIF_API void avifImageFreePlanes(avifImage * image, avifPlanesFlags planes); // Ignores already-freed planes
479+
AVIF_API avifResult avifImageAllocatePlanes(avifImage * image, avifPlanesFlags planes); // Ignores any pre-existing planes
480+
AVIF_API void avifImageFreePlanes(avifImage * image, avifPlanesFlags planes); // Ignores already-freed planes
481481
AVIF_API void avifImageStealPlanes(avifImage * dstImage, avifImage * srcImage, avifPlanesFlags planes);
482482

483483
// ---------------------------------------------------------------------------

src/avif.c

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "avif/internal.h"
55

6+
#include <limits.h>
7+
#include <stdint.h>
68
#include <string.h>
79

810
#define STR_HELPER(x) #x
@@ -163,7 +165,7 @@ static void avifImageCopyNoAlloc(avifImage * dstImage, const avifImage * srcImag
163165
dstImage->imir = srcImage->imir;
164166
}
165167

166-
void avifImageCopy(avifImage * dstImage, const avifImage * srcImage, avifPlanesFlags planes)
168+
avifResult avifImageCopy(avifImage * dstImage, const avifImage * srcImage, avifPlanesFlags planes)
167169
{
168170
avifImageFreePlanes(dstImage, AVIF_PLANES_ALL);
169171
avifImageCopyNoAlloc(dstImage, srcImage);
@@ -174,7 +176,10 @@ void avifImageCopy(avifImage * dstImage, const avifImage * srcImage, avifPlanesF
174176
avifImageSetMetadataXMP(dstImage, srcImage->xmp.data, srcImage->xmp.size);
175177

176178
if ((planes & AVIF_PLANES_YUV) && srcImage->yuvPlanes[AVIF_CHAN_Y]) {
177-
avifImageAllocatePlanes(dstImage, AVIF_PLANES_YUV);
179+
const avifResult allocationResult = avifImageAllocatePlanes(dstImage, AVIF_PLANES_YUV);
180+
if (allocationResult != AVIF_RESULT_OK) {
181+
return allocationResult;
182+
}
178183

179184
avifPixelFormatInfo formatInfo;
180185
avifGetPixelFormatInfo(srcImage->yuvFormat, &formatInfo);
@@ -200,13 +205,17 @@ void avifImageCopy(avifImage * dstImage, const avifImage * srcImage, avifPlanesF
200205
}
201206

202207
if ((planes & AVIF_PLANES_A) && srcImage->alphaPlane) {
203-
avifImageAllocatePlanes(dstImage, AVIF_PLANES_A);
208+
const avifResult allocationResult = avifImageAllocatePlanes(dstImage, AVIF_PLANES_A);
209+
if (allocationResult != AVIF_RESULT_OK) {
210+
return allocationResult;
211+
}
204212
for (uint32_t j = 0; j < dstImage->height; ++j) {
205213
uint8_t * srcAlphaRow = &srcImage->alphaPlane[j * srcImage->alphaRowBytes];
206214
uint8_t * dstAlphaRow = &dstImage->alphaPlane[j * dstImage->alphaRowBytes];
207215
memcpy(dstAlphaRow, srcAlphaRow, dstImage->alphaRowBytes);
208216
}
209217
}
218+
return AVIF_RESULT_OK;
210219
}
211220

212221
avifResult avifImageSetViewRect(avifImage * dstImage, const avifImage * srcImage, const avifCropRect * rect)
@@ -264,45 +273,70 @@ void avifImageSetMetadataXMP(avifImage * image, const uint8_t * xmp, size_t xmpS
264273
avifRWDataSet(&image->xmp, xmp, xmpSize);
265274
}
266275

267-
void avifImageAllocatePlanes(avifImage * image, avifPlanesFlags planes)
276+
avifResult avifImageAllocatePlanes(avifImage * image, avifPlanesFlags planes)
268277
{
269-
int channelSize = avifImageUsesU16(image) ? 2 : 1;
270-
int fullRowBytes = channelSize * image->width;
271-
int fullSize = fullRowBytes * image->height;
278+
if (image->width == 0 || image->height == 0) {
279+
return AVIF_RESULT_INVALID_ARGUMENT;
280+
}
281+
const size_t channelSize = avifImageUsesU16(image) ? 2 : 1;
282+
if (image->width > SIZE_MAX / channelSize) {
283+
return AVIF_RESULT_INVALID_ARGUMENT;
284+
}
285+
const size_t fullRowBytes = channelSize * image->width;
286+
if ((fullRowBytes > UINT32_MAX) || (image->height > SIZE_MAX / fullRowBytes)) {
287+
return AVIF_RESULT_INVALID_ARGUMENT;
288+
}
289+
const size_t fullSize = fullRowBytes * image->height;
290+
272291
if ((planes & AVIF_PLANES_YUV) && (image->yuvFormat != AVIF_PIXEL_FORMAT_NONE)) {
273292
avifPixelFormatInfo info;
274293
avifGetPixelFormatInfo(image->yuvFormat, &info);
275294

276-
int shiftedW = (image->width + info.chromaShiftX) >> info.chromaShiftX;
277-
int shiftedH = (image->height + info.chromaShiftY) >> info.chromaShiftY;
295+
// Intermediary computation as 64 bits in case width or height is exactly UINT32_MAX.
296+
const uint32_t shiftedW = (uint32_t)(((uint64_t)image->width + info.chromaShiftX) >> info.chromaShiftX);
297+
const uint32_t shiftedH = (uint32_t)(((uint64_t)image->height + info.chromaShiftY) >> info.chromaShiftY);
278298

279-
int uvRowBytes = channelSize * shiftedW;
280-
int uvSize = uvRowBytes * shiftedH;
299+
// These are less than or equal to fullRowBytes/fullSize. No need to check overflows.
300+
const size_t uvRowBytes = channelSize * shiftedW;
301+
const size_t uvSize = uvRowBytes * shiftedH;
281302

303+
image->imageOwnsYUVPlanes = AVIF_TRUE;
282304
if (!image->yuvPlanes[AVIF_CHAN_Y]) {
283305
image->yuvRowBytes[AVIF_CHAN_Y] = fullRowBytes;
284306
image->yuvPlanes[AVIF_CHAN_Y] = avifAlloc(fullSize);
307+
if (!image->yuvPlanes[AVIF_CHAN_Y]) {
308+
return AVIF_RESULT_OUT_OF_MEMORY;
309+
}
285310
}
286311

287312
if (image->yuvFormat != AVIF_PIXEL_FORMAT_YUV400) {
288313
if (!image->yuvPlanes[AVIF_CHAN_U]) {
289314
image->yuvRowBytes[AVIF_CHAN_U] = uvRowBytes;
290315
image->yuvPlanes[AVIF_CHAN_U] = avifAlloc(uvSize);
316+
if (!image->yuvPlanes[AVIF_CHAN_U]) {
317+
return AVIF_RESULT_OUT_OF_MEMORY;
318+
}
291319
}
292320
if (!image->yuvPlanes[AVIF_CHAN_V]) {
293321
image->yuvRowBytes[AVIF_CHAN_V] = uvRowBytes;
294322
image->yuvPlanes[AVIF_CHAN_V] = avifAlloc(uvSize);
323+
if (!image->yuvPlanes[AVIF_CHAN_V]) {
324+
return AVIF_RESULT_OUT_OF_MEMORY;
325+
}
295326
}
296327
}
297-
image->imageOwnsYUVPlanes = AVIF_TRUE;
298328
}
299329
if (planes & AVIF_PLANES_A) {
330+
image->imageOwnsAlphaPlane = AVIF_TRUE;
300331
if (!image->alphaPlane) {
301332
image->alphaRowBytes = fullRowBytes;
302333
image->alphaPlane = avifAlloc(fullSize);
334+
if (!image->alphaPlane) {
335+
return AVIF_RESULT_OUT_OF_MEMORY;
336+
}
303337
}
304-
image->imageOwnsAlphaPlane = AVIF_TRUE;
305338
}
339+
return AVIF_RESULT_OK;
306340
}
307341

308342
void avifImageFreePlanes(avifImage * image, avifPlanesFlags planes)

src/read.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,10 @@ static avifBool avifDecoderDataFillImageGrid(avifDecoderData * data,
13631363
}
13641364
}
13651365

1366-
avifImageAllocatePlanes(dstImage, alpha ? AVIF_PLANES_A : AVIF_PLANES_YUV);
1366+
if (avifImageAllocatePlanes(dstImage, alpha ? AVIF_PLANES_A : AVIF_PLANES_YUV) != AVIF_RESULT_OK) {
1367+
avifDiagnosticsPrintf(data->diag, "Image allocation failure");
1368+
return AVIF_FALSE;
1369+
}
13671370

13681371
avifPixelFormatInfo formatInfo;
13691372
avifGetPixelFormatInfo(firstTile->image->yuvFormat, &formatInfo);
@@ -3744,7 +3747,10 @@ static avifResult avifImageLimitedToFullAlpha(avifImage * image)
37443747
// codec's internal frame buffers. Allocate memory for the conversion.
37453748
image->alphaPlane = NULL;
37463749
image->alphaRowBytes = 0;
3747-
avifImageAllocatePlanes(image, AVIF_PLANES_A);
3750+
const avifResult allocationResult = avifImageAllocatePlanes(image, AVIF_PLANES_A);
3751+
if (allocationResult != AVIF_RESULT_OK) {
3752+
return allocationResult;
3753+
}
37483754

37493755
if (image->depth > 8) {
37503756
for (uint32_t j = 0; j < image->height; ++j) {
@@ -4145,8 +4151,7 @@ avifResult avifDecoderRead(avifDecoder * decoder, avifImage * image)
41454151
if (result != AVIF_RESULT_OK) {
41464152
return result;
41474153
}
4148-
avifImageCopy(image, decoder->image, AVIF_PLANES_ALL);
4149-
return AVIF_RESULT_OK;
4154+
return avifImageCopy(image, decoder->image, AVIF_PLANES_ALL);
41504155
}
41514156

41524157
avifResult avifDecoderReadMemory(avifDecoder * decoder, avifImage * image, const uint8_t * data, size_t size)

src/reformat.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,14 @@ avifResult avifImageRGBToYUV(avifImage * image, const avifRGBImage * rgb)
193193
return AVIF_RESULT_NOT_IMPLEMENTED;
194194
}
195195

196+
const avifBool hasAlpha = avifRGBFormatHasAlpha(rgb->format) && !rgb->ignoreAlpha;
197+
avifResult allocationResult = avifImageAllocatePlanes(image, hasAlpha ? AVIF_PLANES_ALL : AVIF_PLANES_YUV);
198+
if (allocationResult != AVIF_RESULT_OK) {
199+
return allocationResult;
200+
}
201+
196202
avifAlphaMultiplyMode alphaMode = AVIF_ALPHA_MULTIPLY_MODE_NO_OP;
197-
avifImageAllocatePlanes(image, AVIF_PLANES_YUV);
198-
if (avifRGBFormatHasAlpha(rgb->format) && !rgb->ignoreAlpha) {
199-
avifImageAllocatePlanes(image, AVIF_PLANES_A);
203+
if (hasAlpha) {
200204
if (!rgb->alphaPremultiplied && image->alphaPremultiplied) {
201205
alphaMode = AVIF_ALPHA_MULTIPLY_MODE_MULTIPLY;
202206
} else if (rgb->alphaPremultiplied && !image->alphaPremultiplied) {

src/scale.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ avifBool avifImageScale(avifImage * image, uint32_t dstWidth, uint32_t dstHeight
8989
}
9090

9191
if (srcYUVPlanes[0]) {
92-
avifImageAllocatePlanes(image, AVIF_PLANES_YUV);
92+
const avifResult allocationResult = avifImageAllocatePlanes(image, AVIF_PLANES_YUV);
93+
if (allocationResult != AVIF_RESULT_OK) {
94+
avifDiagnosticsPrintf(diag, "Allocation of YUV planes failed: %s", avifResultToString(allocationResult));
95+
return AVIF_FALSE;
96+
}
9397

9498
avifPixelFormatInfo formatInfo;
9599
avifGetPixelFormatInfo(image->yuvFormat, &formatInfo);
@@ -132,7 +136,11 @@ avifBool avifImageScale(avifImage * image, uint32_t dstWidth, uint32_t dstHeight
132136
}
133137

134138
if (srcAlphaPlane) {
135-
avifImageAllocatePlanes(image, AVIF_PLANES_A);
139+
const avifResult allocationResult = avifImageAllocatePlanes(image, AVIF_PLANES_A);
140+
if (allocationResult != AVIF_RESULT_OK) {
141+
avifDiagnosticsPrintf(diag, "Allocation of alpha plane failed: %s", avifResultToString(allocationResult));
142+
return AVIF_FALSE;
143+
}
136144

137145
if (image->depth > 8) {
138146
uint16_t * const srcPlane = (uint16_t *)srcAlphaPlane;

0 commit comments

Comments
 (0)