Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove filter in avif_fuzztest_properties #2575

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions tests/gtest/avif_fuzztest_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,35 @@ struct TestProp {
};

void EncodeDecode(ImagePtr image, EncoderPtr encoder, DecoderPtr decoder,
const std::vector<TestProp>& testProps) {
const std::vector<TestProp>& test_props) {
ImagePtr decoded_image(avifImageCreateEmpty());
ASSERT_NE(image.get(), nullptr);
ASSERT_NE(encoder.get(), nullptr);
ASSERT_NE(decoder.get(), nullptr);
ASSERT_NE(decoded_image.get(), nullptr);

for (const TestProp& testProp : testProps) {
std::vector<TestProp> valid_test_properties;
for (const TestProp& testProp : test_props) {
if (testProp.fourcc == std::array<uint8_t, 4>{'u', 'u', 'i', 'd'}) {
ASSERT_EQ(
const avifResult result =
avifImageAddUUIDProperty(image.get(), testProp.uuid.data(),
testProp.body.data(), testProp.body.size()),
AVIF_RESULT_OK);
testProp.body.data(), testProp.body.size());
if (avifIsValidUUID(testProp.uuid.data())) {
valid_test_properties.push_back(testProp);
ASSERT_EQ(result, AVIF_RESULT_OK);
} else {
ASSERT_EQ(result, AVIF_RESULT_INVALID_ARGUMENT);
}
} else {
ASSERT_EQ(avifImageAddOpaqueProperty(image.get(), testProp.fourcc.data(),
testProp.body.data(),
testProp.body.size()),
AVIF_RESULT_OK);
const avifResult result = avifImageAddOpaqueProperty(
image.get(), testProp.fourcc.data(), testProp.body.data(),
testProp.body.size());
if (avifIsKnownPropertyType(testProp.fourcc.data())) {
ASSERT_EQ(result, AVIF_RESULT_INVALID_ARGUMENT);
} else {
valid_test_properties.push_back(testProp);
ASSERT_EQ(result, AVIF_RESULT_OK);
}
}
}

Expand All @@ -57,9 +68,9 @@ void EncodeDecode(ImagePtr image, EncoderPtr encoder, DecoderPtr decoder,
ASSERT_EQ(decoder_result, AVIF_RESULT_OK)
<< avifResultToString(decoder_result);

ASSERT_EQ(decoder->image->numProperties, testProps.size());
for (size_t i = 0; i < testProps.size(); i++) {
const TestProp& testProp = testProps[i];
ASSERT_EQ(decoder->image->numProperties, valid_test_properties.size());
for (size_t i = 0; i < valid_test_properties.size(); i++) {
const TestProp& testProp = valid_test_properties[i];
const avifImageItemProperty& decodeProp = decoder->image->properties[i];
EXPECT_EQ(std::string(decodeProp.boxtype, decodeProp.boxtype + 4),
std::string(testProp.fourcc.data(), testProp.fourcc.data() + 4));
Expand All @@ -74,22 +85,14 @@ inline auto ArbitraryProp() {
auto fourcc = fuzztest::Arbitrary<std::array<uint8_t, 4>>();
auto uuid = fuzztest::Arbitrary<std::array<uint8_t, 16>>(); // ignored
auto body = fuzztest::Arbitrary<std::vector<uint8_t>>();
// Don't return known properties.
return fuzztest::Filter(
[](const TestProp& prop) {
return !avifIsKnownPropertyType(prop.fourcc.data());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A random fourcc is unlikely to be a known property type. So this Filter should be okay.

},
fuzztest::StructOf<TestProp>(fourcc, uuid, body));
return fuzztest::StructOf<TestProp>(fourcc, uuid, body);
}

inline auto ArbitraryUUIDProp() {
auto fourcc = fuzztest::Just(std::array<uint8_t, 4>{'u', 'u', 'i', 'd'});
auto uuid = fuzztest::Arbitrary<std::array<uint8_t, 16>>();
auto body = fuzztest::Arbitrary<std::vector<uint8_t>>();
// Don't use invalid UUIDs.
return fuzztest::Filter(
[](const TestProp& prop) { return avifIsValidUUID(prop.uuid.data()); },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess a random 16-byte is likely to be an invalid UUID more than 90% of the time in the first 100 tries. It may make sense to replace line 87 (auto uuid = fuzztest::Arbitrary<std::array<uint8_t, 16>>();) with custom code that generates a valid UUID.

fuzztest::StructOf<TestProp>(fourcc, uuid, body));
return fuzztest::StructOf<TestProp>(fourcc, uuid, body);
}

inline auto ArbitraryProps() {
Expand Down
Loading