Fuzz gainmap API Apply clang-format. Change-Id: Ia9e0702cd12731a077d21ab9fb3a336818271b2d
diff --git a/avifinfo.h b/avifinfo.h index 266c714..e95abf7 100644 --- a/avifinfo.h +++ b/avifinfo.h
@@ -35,15 +35,16 @@ } AvifInfoStatus; typedef struct { - uint32_t width, height; // In number of pixels. Ignores mirror and rotation. - uint32_t bit_depth; // Likely 8, 10 or 12 bits per channel per pixel. - uint32_t num_channels; // Likely 1, 2, 3 or 4 channels: - // (1 monochrome or 3 colors) + (0 or 1 alpha) - uint8_t has_gainmap; // True if a gain map was found. - uint8_t gainmap_item_id; // Id of the gain map item. + uint32_t width, height; // In number of pixels. Ignores mirror and rotation. + uint32_t bit_depth; // Likely 8, 10 or 12 bits per channel per pixel. + uint32_t num_channels; // Likely 1, 2, 3 or 4 channels: + // (1 monochrome or 3 colors) + (0 or 1 alpha) + uint8_t has_gainmap; // True if a gain map was found. + uint8_t gainmap_item_id; // Id of the gain map item. // Start location of the primary item id, in bytes. // The primary item id is a big endian number stored on bytes - // primary_item_id_location to primary_item_id_location+primary_item_id_bytes. + // primary_item_id_location to + // primary_item_id_location+primary_item_id_bytes-1 inclusive. uint64_t primary_item_id_location; // Number of bytes of the primary item id. uint8_t primary_item_id_bytes;
diff --git a/tests/avifinfo_fuzz.cc b/tests/avifinfo_fuzz.cc index 8499b72..1be3421 100644 --- a/tests/avifinfo_fuzz.cc +++ b/tests/avifinfo_fuzz.cc
@@ -77,17 +77,34 @@ if (features.width != previous_features.width || features.height != previous_features.height || features.bit_depth != previous_features.bit_depth || - features.num_channels != previous_features.num_channels) { + features.num_channels != previous_features.num_channels || + features.has_gainmap != previous_features.has_gainmap || + features.gainmap_item_id != previous_features.gainmap_item_id || + features.primary_item_id_location != + previous_features.primary_item_id_location || + features.primary_item_id_bytes != + previous_features.primary_item_id_bytes) { std::abort(); } } else if (status_features == kAvifInfoOk) { if (features.width == 0u || features.height == 0u || - features.bit_depth == 0u || features.num_channels == 0u) { + features.bit_depth == 0u || features.num_channels == 0u || + !features.has_gainmap != !features.gainmap_item_id || + !features.primary_item_id_location != + !features.primary_item_id_bytes) { + std::abort(); + } + if (features.primary_item_id_location && + features.primary_item_id_location + features.primary_item_id_bytes > + size) { std::abort(); } } else { if (features.width != 0u || features.height != 0u || - features.bit_depth != 0u || features.num_channels != 0u) { + features.bit_depth != 0u || features.num_channels != 0u || + features.has_gainmap != 0u || features.gainmap_item_id != 0u || + features.primary_item_id_location != 0u || + features.primary_item_id_bytes != 0u) { std::abort(); } }
diff --git a/tests/avifinfo_test.cc b/tests/avifinfo_test.cc index f7fcfc2..94f2b3c 100644 --- a/tests/avifinfo_test.cc +++ b/tests/avifinfo_test.cc
@@ -46,7 +46,8 @@ return true; } -void ExpectEqual(const AvifInfoFeatures& actual, const AvifInfoFeatures& expected) { +void ExpectEqual(const AvifInfoFeatures& actual, + const AvifInfoFeatures& expected) { EXPECT_EQ(actual.width, expected.width); EXPECT_EQ(actual.height, expected.height); EXPECT_EQ(actual.bit_depth, expected.bit_depth); @@ -90,7 +91,6 @@ .has_gainmap = 0u, .primary_item_id_location = 96u, .primary_item_id_bytes = 2u}); - } TEST(AvifInfoGetTest, WithGainmap) { @@ -127,7 +127,6 @@ .primary_item_id_bytes = 2u}); } - TEST(AvifInfoGetTest, NoPixi10b) { // Same as above but "meta" box size is stored as 64 bits, "av1C" has // 'high_bitdepth' set to true, "pixi" was renamed to "pixy" and "mdat" size @@ -146,7 +145,6 @@ .has_gainmap = 0u, .primary_item_id_location = 104u, .primary_item_id_bytes = 2u}); - } TEST(AvifInfoGetTest, EnoughBytes) {