Skip to content

Commit 2340467

Browse files
committed
Restrict sato image item's depth to 8,10,12,16
Restrict sample transform derived image item's bit depth to 8, 10, 12, and 16, which are supported by commonly-used libraries such as libyuv.
1 parent 3c2a66a commit 2340467

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/read.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,6 +2308,12 @@ static avifResult avifDecoderSampleTransformItemValidateProperties(const avifDec
23082308
// This is enforced in avifParsePixelInformationProperty().
23092309
AVIF_ASSERT_OR_RETURN(pixiProp->u.pixi.planeDepths[i] == pixiProp->u.pixi.planeDepths[0]);
23102310
}
2311+
AVIF_ASSERT_OR_RETURN(pixiProp->u.pixi.planeCount >= 1);
2312+
const uint8_t depth = pixiProp->u.pixi.planeDepths[0];
2313+
if (depth != 8 && depth != 10 && depth != 12 && depth != 16) {
2314+
avifDiagnosticsPrintf(diag, "Item ID %u depth specified by pixi property [%u] is not supported", item->id, depth);
2315+
return AVIF_RESULT_NOT_IMPLEMENTED;
2316+
}
23112317

23122318
const avifProperty * ispeProp = avifPropertyArrayFind(&item->properties, "ispe");
23132319
if (!ispeProp) {

tests/gtest/avif16bittest.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,10 @@ TEST(Avif16bitTest, SampleTransformWithOtherBitDepths) {
430430
const avifResult result = avifDecoderReadMemory(
431431
decoder.get(), decoded.get(), encoded.data(), encoded.size());
432432
const avifResult expected_result =
433-
num_bits == 0 ? AVIF_RESULT_BMFF_PARSE_FAILED
434-
: num_bits > 16 ? AVIF_RESULT_NOT_IMPLEMENTED
435-
: AVIF_RESULT_OK;
433+
num_bits == 0 ? AVIF_RESULT_BMFF_PARSE_FAILED
434+
: (num_bits == 8 || num_bits == 10 || num_bits == 12 || num_bits == 16)
435+
? AVIF_RESULT_OK
436+
: AVIF_RESULT_NOT_IMPLEMENTED;
436437
ASSERT_EQ(result, expected_result) << "bits_per_channels " << num_bits;
437438
if (result == AVIF_RESULT_OK) {
438439
// The output image should be highly distorted because of the pixel value

0 commit comments

Comments
 (0)