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

Fix common type target for reserved type names (3.4.x) #495

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 7 additions & 5 deletions cedar-drt/fuzz/fuzz_targets/abac-type-directed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use cedar_policy_generators::{
schema::Schema,
settings::ABACSettings,
};
use libfuzzer_sys::arbitrary::{self, Arbitrary, Unstructured};
use libfuzzer_sys::arbitrary::{self, Arbitrary, MaxRecursionReached, Unstructured};
use log::{debug, info};
use serde::Serialize;
use std::convert::TryFrom;
Expand Down Expand Up @@ -91,9 +91,11 @@ impl<'a> Arbitrary<'a> for FuzzTargetInput {
})
}

fn size_hint(depth: usize) -> (usize, Option<usize>) {
arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth),
fn try_size_hint(
depth: usize,
) -> std::result::Result<(usize, Option<usize>), MaxRecursionReached> {
Ok(arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth)?,
HierarchyGenerator::size_hint(depth),
Schema::arbitrary_policy_size_hint(&SETTINGS, depth),
Schema::arbitrary_request_size_hint(depth),
Expand All @@ -104,7 +106,7 @@ impl<'a> Arbitrary<'a> for FuzzTargetInput {
Schema::arbitrary_request_size_hint(depth),
Schema::arbitrary_request_size_hint(depth),
Schema::arbitrary_request_size_hint(depth),
])
]))
}
}

Expand Down
12 changes: 7 additions & 5 deletions cedar-drt/fuzz/fuzz_targets/abac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use cedar_policy_generators::{
schema::Schema,
settings::ABACSettings,
};
use libfuzzer_sys::arbitrary::{self, Arbitrary, Unstructured};
use libfuzzer_sys::arbitrary::{self, Arbitrary, MaxRecursionReached, Unstructured};
use log::{debug, info};
use serde::Serialize;
use std::convert::TryFrom;
Expand Down Expand Up @@ -90,9 +90,11 @@ impl<'a> Arbitrary<'a> for FuzzTargetInput {
})
}

fn size_hint(depth: usize) -> (usize, Option<usize>) {
arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth),
fn try_size_hint(
depth: usize,
) -> std::result::Result<(usize, Option<usize>), MaxRecursionReached> {
Ok(arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth)?,
HierarchyGenerator::size_hint(depth),
Schema::arbitrary_policy_size_hint(&SETTINGS, depth),
Schema::arbitrary_request_size_hint(depth),
Expand All @@ -103,7 +105,7 @@ impl<'a> Arbitrary<'a> for FuzzTargetInput {
Schema::arbitrary_request_size_hint(depth),
Schema::arbitrary_request_size_hint(depth),
Schema::arbitrary_request_size_hint(depth),
])
]))
}
}

Expand Down
24 changes: 17 additions & 7 deletions cedar-drt/fuzz/fuzz_targets/common-type-resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
use cedar_drt_inner::{schemas::validator_schema_attr_types_equivalent, *};
use cedar_policy_generators::{schema::Schema, settings::ABACSettings};
use cedar_policy_validator::SchemaFragment;
use libfuzzer_sys::arbitrary::{self, Arbitrary, Unstructured};
use libfuzzer_sys::arbitrary::{self, Arbitrary, MaxRecursionReached, Unstructured};
use log::info;
use serde::Serialize;
use similar_asserts::SimpleDiff;
use std::collections::HashMap;

#[derive(Debug, Clone, Serialize)]
Expand Down Expand Up @@ -67,7 +68,9 @@ impl<'a> Arbitrary<'a> for Input {
})
}

fn size_hint(depth: usize) -> (usize, Option<usize>) {
fn try_size_hint(
depth: usize,
) -> std::result::Result<(usize, Option<usize>), MaxRecursionReached> {
Schema::arbitrary_size_hint(depth)
}
}
Expand All @@ -81,14 +84,21 @@ fuzz_target!(|i: Input| {
(Ok(s1), Ok(s2)) => {
assert!(
validator_schema_attr_types_equivalent(&s1, &s2),
"reduced to different validator schemas: {:?}\n{:?}\n",
s1,
s2
"{}",
SimpleDiff::from_str(
&format!("{s1:?}"),
&format!("{s2:?}"),
"original",
"with common types"
)
);
}
(Err(_), Err(_)) => {}
(Ok(s), Err(_)) | (Err(_), Ok(s)) => {
panic!("reduction results differ, got validator schema: {:?}\n", s);
(Ok(s), Err(e)) => {
panic!("Constructed schema without common types but failed to build schema with common types.\nconstructed schema:\n{s:#?}\nerror: {e:?}")
}
(Err(e), Ok(s)) => {
panic!("Constructed schema with common types but failed to build schema without common types.\nconstructed schema:\n{s:#?}\nerror: {e:?}")
}
}
});
12 changes: 7 additions & 5 deletions cedar-drt/fuzz/fuzz_targets/eval-type-directed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use cedar_policy_generators::err::Error;
use cedar_policy_generators::hierarchy::HierarchyGenerator;
use cedar_policy_generators::schema::{arbitrary_schematype_with_bounded_depth, Schema};
use cedar_policy_generators::settings::ABACSettings;
use libfuzzer_sys::arbitrary::{self, Arbitrary, Unstructured};
use libfuzzer_sys::arbitrary::{self, Arbitrary, MaxRecursionReached, Unstructured};
use log::debug;
use serde::Serialize;
use std::convert::TryFrom;
Expand Down Expand Up @@ -88,9 +88,11 @@ impl<'a> Arbitrary<'a> for FuzzTargetInput {
})
}

fn size_hint(depth: usize) -> (usize, Option<usize>) {
arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth),
fn try_size_hint(
depth: usize,
) -> std::result::Result<(usize, Option<usize>), MaxRecursionReached> {
Ok(arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth)?,
HierarchyGenerator::size_hint(depth),
Schema::arbitrary_policy_size_hint(&SETTINGS, depth),
Schema::arbitrary_request_size_hint(depth),
Expand All @@ -101,7 +103,7 @@ impl<'a> Arbitrary<'a> for FuzzTargetInput {
Schema::arbitrary_request_size_hint(depth),
Schema::arbitrary_request_size_hint(depth),
Schema::arbitrary_request_size_hint(depth),
])
]))
}
}

Expand Down
12 changes: 7 additions & 5 deletions cedar-drt/fuzz/fuzz_targets/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use cedar_policy_formatter::{lexer, policies_str_to_pretty, Config};
use cedar_policy_generators::{
abac::ABACPolicy, hierarchy::HierarchyGenerator, schema::Schema, settings::ABACSettings,
};
use libfuzzer_sys::arbitrary::{self, Arbitrary, Unstructured};
use libfuzzer_sys::arbitrary::{self, Arbitrary, MaxRecursionReached, Unstructured};
use log::debug;
use serde::Serialize;
use similar_asserts::SimpleDiff;
Expand Down Expand Up @@ -63,12 +63,14 @@ impl<'a> Arbitrary<'a> for FuzzTargetInput {
Ok(Self { policy })
}

fn size_hint(depth: usize) -> (usize, Option<usize>) {
arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth),
fn try_size_hint(
depth: usize,
) -> std::result::Result<(usize, Option<usize>), MaxRecursionReached> {
Ok(arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth)?,
HierarchyGenerator::size_hint(depth),
Schema::arbitrary_policy_size_hint(&SETTINGS, depth),
])
]))
}
}

Expand Down
6 changes: 4 additions & 2 deletions cedar-drt/fuzz/fuzz_targets/json-schema-roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use cedar_drt_inner::schemas::equivalence_check;
use cedar_drt_inner::*;
use cedar_policy_generators::{schema::Schema, settings::ABACSettings};
use cedar_policy_validator::SchemaFragment;
use libfuzzer_sys::arbitrary::{self, Arbitrary, Unstructured};
use libfuzzer_sys::arbitrary::{self, Arbitrary, MaxRecursionReached, Unstructured};
use serde::Serialize;
use std::collections::HashMap;

Expand Down Expand Up @@ -57,7 +57,9 @@ impl<'a> Arbitrary<'a> for Input {
Ok(Self { schema })
}

fn size_hint(depth: usize) -> (usize, Option<usize>) {
fn try_size_hint(
depth: usize,
) -> std::result::Result<(usize, Option<usize>), MaxRecursionReached> {
Schema::arbitrary_size_hint(depth)
}
}
Expand Down
11 changes: 7 additions & 4 deletions cedar-drt/fuzz/fuzz_targets/partial-eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use cedar_policy_generators::{
schema::Schema,
settings::ABACSettings,
};
use libfuzzer_sys::arbitrary::MaxRecursionReached;
use libfuzzer_sys::arbitrary::{self, Arbitrary, Unstructured};
use log::debug;
use serde::Serialize;
Expand Down Expand Up @@ -100,9 +101,11 @@ impl<'a> Arbitrary<'a> for FuzzTargetInput {
})
}

fn size_hint(depth: usize) -> (usize, Option<usize>) {
arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth),
fn try_size_hint(
depth: usize,
) -> std::result::Result<(usize, Option<usize>), MaxRecursionReached> {
Ok(arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth)?,
HierarchyGenerator::size_hint(depth),
Schema::arbitrary_policy_size_hint(&SETTINGS, depth),
Schema::arbitrary_request_size_hint(depth),
Expand All @@ -113,7 +116,7 @@ impl<'a> Arbitrary<'a> for FuzzTargetInput {
Schema::arbitrary_request_size_hint(depth),
Schema::arbitrary_request_size_hint(depth),
Schema::arbitrary_request_size_hint(depth),
])
]))
}
}

Expand Down
12 changes: 7 additions & 5 deletions cedar-drt/fuzz/fuzz_targets/roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use cedar_policy_core::parser::{self, parse_policy};
use cedar_policy_generators::{
abac::ABACPolicy, hierarchy::HierarchyGenerator, schema::Schema, settings::ABACSettings,
};
use libfuzzer_sys::arbitrary::{self, Arbitrary, Unstructured};
use libfuzzer_sys::arbitrary::{self, Arbitrary, MaxRecursionReached, Unstructured};
use log::debug;
use serde::Serialize;
use smol_str::SmolStr;
Expand Down Expand Up @@ -61,12 +61,14 @@ impl<'a> Arbitrary<'a> for FuzzTargetInput {
Ok(Self { policy })
}

fn size_hint(depth: usize) -> (usize, Option<usize>) {
arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth),
fn try_size_hint(
depth: usize,
) -> std::result::Result<(usize, Option<usize>), MaxRecursionReached> {
Ok(arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth)?,
HierarchyGenerator::size_hint(depth),
Schema::arbitrary_policy_size_hint(&SETTINGS, depth),
])
]))
}
}

Expand Down
6 changes: 4 additions & 2 deletions cedar-drt/fuzz/fuzz_targets/schema-roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use cedar_drt_inner::schemas::equivalence_check;
use cedar_drt_inner::*;
use cedar_policy_generators::{schema::Schema, settings::ABACSettings};
use cedar_policy_validator::SchemaFragment;
use libfuzzer_sys::arbitrary::{self, Arbitrary, Unstructured};
use libfuzzer_sys::arbitrary::{self, Arbitrary, MaxRecursionReached, Unstructured};
use serde::Serialize;
use std::collections::HashMap;

Expand Down Expand Up @@ -57,7 +57,9 @@ impl<'a> Arbitrary<'a> for Input {
Ok(Self { schema })
}

fn size_hint(depth: usize) -> (usize, Option<usize>) {
fn try_size_hint(
depth: usize,
) -> std::result::Result<(usize, Option<usize>), MaxRecursionReached> {
Schema::arbitrary_size_hint(depth)
}
}
Expand Down
12 changes: 7 additions & 5 deletions cedar-drt/fuzz/fuzz_targets/validation-drt-type-directed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use cedar_drt::*;
use cedar_drt_inner::*;
use cedar_policy_core::ast;
use cedar_policy_generators::{abac::ABACPolicy, schema::Schema, settings::ABACSettings};
use libfuzzer_sys::arbitrary::{self, Arbitrary, Unstructured};
use libfuzzer_sys::arbitrary::{self, Arbitrary, MaxRecursionReached, Unstructured};
use log::{debug, info};
use serde::Serialize;

Expand Down Expand Up @@ -56,11 +56,13 @@ impl<'a> Arbitrary<'a> for FuzzTargetInput {
Ok(Self { schema, policy })
}

fn size_hint(depth: usize) -> (usize, Option<usize>) {
arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth),
fn try_size_hint(
depth: usize,
) -> std::result::Result<(usize, Option<usize>), MaxRecursionReached> {
Ok(arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth)?,
Schema::arbitrary_policy_size_hint(&SETTINGS, depth),
])
]))
}
}

Expand Down
12 changes: 7 additions & 5 deletions cedar-drt/fuzz/fuzz_targets/validation-drt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use cedar_drt::*;
use cedar_drt_inner::*;
use cedar_policy_core::ast;
use cedar_policy_generators::{abac::ABACPolicy, schema::Schema, settings::ABACSettings};
use libfuzzer_sys::arbitrary::{self, Arbitrary, Unstructured};
use libfuzzer_sys::arbitrary::{self, Arbitrary, MaxRecursionReached, Unstructured};
use log::{debug, info};
use serde::Serialize;

Expand Down Expand Up @@ -56,11 +56,13 @@ impl<'a> Arbitrary<'a> for FuzzTargetInput {
Ok(Self { schema, policy })
}

fn size_hint(depth: usize) -> (usize, Option<usize>) {
arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth),
fn try_size_hint(
depth: usize,
) -> std::result::Result<(usize, Option<usize>), MaxRecursionReached> {
Ok(arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth)?,
Schema::arbitrary_policy_size_hint(&SETTINGS, depth),
])
]))
}
}

Expand Down
12 changes: 7 additions & 5 deletions cedar-drt/fuzz/fuzz_targets/validation-pbt-type-directed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use cedar_policy_generators::{
settings::ABACSettings,
};
use cedar_policy_validator::{ValidationMode, Validator, ValidatorSchema};
use libfuzzer_sys::arbitrary::{self, Arbitrary, Unstructured};
use libfuzzer_sys::arbitrary::{self, Arbitrary, MaxRecursionReached, Unstructured};
use log::debug;
use serde::Serialize;
use std::convert::TryFrom;
Expand Down Expand Up @@ -89,9 +89,11 @@ impl<'a> Arbitrary<'a> for FuzzTargetInput {
})
}

fn size_hint(depth: usize) -> (usize, Option<usize>) {
arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth),
fn try_size_hint(
depth: usize,
) -> std::result::Result<(usize, Option<usize>), MaxRecursionReached> {
Ok(arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth)?,
HierarchyGenerator::size_hint(depth),
Schema::arbitrary_policy_size_hint(&SETTINGS, depth),
Schema::arbitrary_request_size_hint(depth),
Expand All @@ -102,7 +104,7 @@ impl<'a> Arbitrary<'a> for FuzzTargetInput {
Schema::arbitrary_request_size_hint(depth),
Schema::arbitrary_request_size_hint(depth),
Schema::arbitrary_request_size_hint(depth),
])
]))
}
}

Expand Down
12 changes: 7 additions & 5 deletions cedar-drt/fuzz/fuzz_targets/validation-pbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use cedar_policy_generators::{
use cedar_policy_validator::{
ApplySpec, NamespaceDefinition, ValidationMode, Validator, ValidatorSchema,
};
use libfuzzer_sys::arbitrary::{self, Arbitrary, Unstructured};
use libfuzzer_sys::arbitrary::{self, Arbitrary, MaxRecursionReached, Unstructured};
use log::debug;
use serde::Serialize;
use std::convert::TryFrom;
Expand Down Expand Up @@ -298,9 +298,11 @@ impl<'a> Arbitrary<'a> for FuzzTargetInput {
})
}

fn size_hint(depth: usize) -> (usize, Option<usize>) {
arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth),
fn try_size_hint(
depth: usize,
) -> std::result::Result<(usize, Option<usize>), MaxRecursionReached> {
Ok(arbitrary::size_hint::and_all(&[
Schema::arbitrary_size_hint(depth)?,
HierarchyGenerator::size_hint(depth),
Schema::arbitrary_policy_size_hint(&SETTINGS, depth),
Schema::arbitrary_request_size_hint(depth),
Expand All @@ -311,7 +313,7 @@ impl<'a> Arbitrary<'a> for FuzzTargetInput {
Schema::arbitrary_request_size_hint(depth),
Schema::arbitrary_request_size_hint(depth),
Schema::arbitrary_request_size_hint(depth),
])
]))
}
}

Expand Down
Loading
Loading