aaf: bound duplicate property detection work

This commit is contained in:
Dylan M. Taylor committed 2026-11-15 16:00:14 +00:00
1 parent 52a6dd6aa7
commit 99e448d919
2 files changed
+19 -1

No files matched your search

+16
View File
@@ -108,3 +108,19 @@ fn objects_nested_too_deeply_are_an_error() {
let e = store::read(&chain(250)).unwrap_err();
assert!(e.contains("nested too deeply"), "{e}");
}
/// Many distinct property IDs still reject a duplicate without quadratic scanning.
#[test]
fn duplicate_after_many_distinct_properties_is_rejected() {
let mut props = vec![0x4C, 0x20];
props.extend_from_slice(&8193u16.to_le_bytes());
for id in (0..8192u16).chain(std::iter::once(7)) {
props.extend_from_slice(&id.to_le_bytes());
props.extend_from_slice(&0x82u16.to_le_bytes());
props.extend_from_slice(&0u16.to_le_bytes());
}
let mut writer = Writer::new(Version::V3);
writer.stream(Writer::ROOT, "properties", props).unwrap();
let e = store::read(&writer.finish()).unwrap_err();
assert!(e.contains("duplicate property id"), "{e}");
}
+3 -1
View File
@@ -461,11 +461,13 @@ impl R<'_> {
if at > props.len() {
return Err(bad("truncated property index"));
}
// A properties stream can name tens of thousands of ids: do not rescan all earlier ids.
let mut seen = std::collections::HashSet::with_capacity(n);
for i in 0..n {
let (Some(pid), Some(sf), Some(len)) = (rd_u16(&props, 4 + i * 6), rd_u16(&props, 6 + i * 6), rd_u16(&props, 8 + i * 6)) else {
return Err(bad("truncated property index"));
};
if o.props.iter().any(|(previous, _)| *previous == pid) {
if !seen.insert(pid) {
return Err(bad("duplicate property id"));
}
let v = props.get(at..at + len as usize).ok_or_else(|| bad("truncated property value"))?;