mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
04396dd85f
commit
7c77143b97
1 file changed
+15
-1
+15
-1
@@ -155,7 +155,8 @@ impl PathData {
|
||||
out.push(PsdSubpath {
|
||||
closed: r.selector == selector::CLOSED_LENGTH,
|
||||
operation: r.u16_at(2) as i16,
|
||||
knots: Vec::with_capacity(remaining.min(4096)),
|
||||
// No preallocation: the count is untrusted (u16) and PsdKnot is 56 bytes.
|
||||
knots: Vec::new(),
|
||||
});
|
||||
} else if r.is_knot() {
|
||||
let closed = r.selector <= 2;
|
||||
@@ -261,6 +262,19 @@ mod tests {
|
||||
]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subpaths_does_not_preallocate_from_untrusted_counts() {
|
||||
let mut bytes = Vec::new();
|
||||
for _ in 0..100_000 {
|
||||
bytes.extend_from_slice(&selector::CLOSED_LENGTH.to_be_bytes());
|
||||
bytes.extend_from_slice(&0xFFFFu16.to_be_bytes());
|
||||
bytes.extend_from_slice(&[0u8; 22]);
|
||||
}
|
||||
let subs = PathData::from_bytes(&bytes).unwrap().subpaths();
|
||||
assert_eq!(subs.len(), 100_000);
|
||||
assert!(subs.iter().all(|s| s.knots.capacity() == 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subpaths_roundtrip_and_bytes_are_stable() {
|
||||
let p = PathData::from_subpaths(&sample(), true);
|
||||
|
||||
Reference in new issue
Block a user