mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
svg: fix bounded non-strict embedded SVG limit handling and test assertions
This commit is contained in:
1 parent
3636faa008
commit
c2689ba214
2 files changed
+12
-4
No files matched your search
@@ -557,7 +557,7 @@ fn parse_image_bounded_with(
|
||||
counter.svg_chain = usage.embedded_svg_depth as u64;
|
||||
if usage.raster_limit_images > 0 {
|
||||
counter.error.get_or_insert_with(|| "embedded SVG raster images exceed the decoded pixel budget".into());
|
||||
} else if usage.svg_limit_images > 0 {
|
||||
} else if counter.strict && usage.svg_limit_images > 0 {
|
||||
counter.error.get_or_insert_with(|| "embedded SVG images exceed the byte or nesting budget".into());
|
||||
} else if counter.strict && (usage.invalid_raster_images > 0 || usage.invalid_svg_images > 0) {
|
||||
counter.error.get_or_insert_with(|| "can't parse an embedded SVG image".into());
|
||||
|
||||
@@ -46,7 +46,7 @@ fn non_strict_embedded_svg_records_isolation_failure_but_omits_invalid_images()
|
||||
parse_image_bounded_with(invalid.as_bytes(), budget.clone(), MAX_XML_DEPTH, inter_only, false).unwrap();
|
||||
assert!(budget.lock().unwrap().error.is_none(), "ordinary invalid images are still omitted");
|
||||
let svg = image_svg("<text>x</text>");
|
||||
let error = parse_image_bounded_with(svg.as_bytes(), budget.clone(), 1, panic_fonts, false).unwrap_err();
|
||||
let error = parse_image_bounded_with(svg.as_bytes(), budget.clone(), 2, panic_fonts, false).unwrap_err();
|
||||
assert!(error.to_string().contains("bounded SVG worker failed"));
|
||||
assert_eq!(budget.lock().unwrap().error.as_deref(), Some(error.to_string().as_str()));
|
||||
}
|
||||
@@ -1336,8 +1336,16 @@ fn nested_shared_patterns_add_up_their_depth() {
|
||||
let body: String = (0..k).rev().map(|i| format!("<rect width=\"10\" height=\"10\" fill=\"url(#D{i})\"/>")).collect();
|
||||
let svg = format!("<svg {NS} width=\"100\" height=\"100\"><defs>{defs}</defs>{body}</svg>");
|
||||
// 9,500 nested groups: usvg's conversion overflows the 2 MiB test-thread stack on Windows.
|
||||
let err = std::thread::Builder::new().stack_size(64 << 20).spawn(move || check_only(&svg, 100, 100).unwrap_err()).unwrap().join().unwrap();
|
||||
assert!(err.message.contains("layers"), "{err:?}");
|
||||
let msg = std::thread::Builder::new()
|
||||
.stack_size(64 << 20)
|
||||
.spawn(move || match parse(svg.as_bytes()) {
|
||||
Err(e) => e.to_string(),
|
||||
Ok(p) => limits::check(p.tree.root().children(), tiny_skia::Transform::identity(), 100, 100, 0).unwrap_err().message,
|
||||
})
|
||||
.unwrap()
|
||||
.join()
|
||||
.unwrap();
|
||||
assert!(msg.contains("layers"), "{msg}");
|
||||
}
|
||||
|
||||
/// usvg makes the layer the union of a group's filter regions and every unary primitive on it keeps
|
||||
|
||||
Reference in new issue
Block a user