Skip to content
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
2 changes: 1 addition & 1 deletion crates/data/src/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ fn close(prefixes: &mut HashMap<&[u8], usize>, prefix: &[u8]) {
}

/// Whether a DOCTYPE declares an entity whose value holds markup (a `<`).
fn entity_with_markup(decl: &[u8]) -> bool {
pub fn entity_with_markup(decl: &[u8]) -> bool {
let mut at = 0;
while let Some(p) = decl.get(at..).and_then(|r| r.windows(8).position(|w| w == b"<!ENTITY")) {
let start = at + p + 8;
Expand Down
10 changes: 8 additions & 2 deletions crates/engine/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2241,11 +2241,12 @@ pub(crate) fn picture_notices_by<'a>(
*seen.borrow_mut().entry(p).or_insert_with(|| check(p))
};
// The names with an image refused so, by each refusal in `WHY`, in the order their notices go.
const WHY: [MarkerRefusal; 10] = [
const WHY: [MarkerRefusal; 11] = [
MarkerRefusal::NotAnImage,
MarkerRefusal::TooManyBytes,
MarkerRefusal::TooManyPixels,
MarkerRefusal::TooMuchToDraw,
MarkerRefusal::SvgTooMuchToRead,
MarkerRefusal::SvgTooNested,
MarkerRefusal::SvgUnknownRadius,
MarkerRefusal::SvgTooSmall,
Expand Down Expand Up @@ -2294,7 +2295,8 @@ pub(crate) fn picture_notices_by<'a>(
],
));
}
let [not_images, too_long, too_large, too_much, too_nested, unknown_radius, too_small, not_utf8, filtered, past_run] = &bad;
let [not_images, too_long, too_large, too_much, too_much_to_read, too_nested, unknown_radius, too_small, not_utf8, filtered, past_run] =
&bad;
if !not_images.is_empty() {
notices.push(NoticeText::format(
"Image markers in {names} aren't PNG, JPEG or SVG images and are drawn as circles",
Expand All @@ -2321,6 +2323,10 @@ pub(crate) fn picture_notices_by<'a>(
}
// Each SVG's own cause (#2713), its figures as the renderer's phrase gives them.
for (names, what) in [
(
too_much_to_read,
"Image markers in {names} are SVGs whose style sheets, element attributes or entities holding tags take more to read than RustGIS allows and are drawn as circles",
),
(
too_nested,
"Image markers in {names} are SVGs with more than 40,000 XML nodes or nested deeper than 64 levels and are drawn as circles",
Expand Down
4 changes: 4 additions & 0 deletions crates/engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2747,6 +2747,10 @@ fn svg_image_markers_that_dont_draw_are_said_with_why() {
"Image markers in \"Cities\", \"Rivers\" are SVGs with filters, text, images, animation or links to other files, which RustGIS doesn't draw in marker images, and are drawn as circles",
),
(MarkerRefusal::TooManyBytes, "Image markers in \"Cities\", \"Rivers\" are longer than 2 MiB as base64 and are drawn as circles"),
(
MarkerRefusal::SvgTooMuchToRead,
"Image markers in \"Cities\", \"Rivers\" are SVGs whose style sheets, element attributes or entities holding tags take more to read than RustGIS allows and are drawn as circles",
),
(
MarkerRefusal::SvgTooNested,
"Image markers in \"Cities\", \"Rivers\" are SVGs with more than 40,000 XML nodes or nested deeper than 64 levels and are drawn as circles",
Expand Down
11 changes: 10 additions & 1 deletion crates/render/src/picture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ pub enum MarkerRefusal {
/// It is an SVG with more to draw than [`MARKER_PIXELS`] (in the units of the renderer's SVG
/// count, `svg::work`), or more elements than `svg::ELEMENTS` (10,000).
TooMuchToDraw,
/// It is an SVG whose style sheets and `style` attributes, or whose elements' attributes, take
/// more to read than `svg::STYLE_UNITS` and `svg::ATTRIBUTE_PAIRS` allow, or whose entities
/// hold tags, which no count sees.
SvgTooMuchToRead,
/// It is an SVG with more XML nodes than `svg::XML_NODES` (40,000) or nested deeper than
/// `svg::DEPTH` (64).
SvgTooNested,
Expand Down Expand Up @@ -136,6 +140,7 @@ refusal_phrases! {
TooManyBytes => "is longer than 2 MiB as base64",
TooManyPixels => "has more pixels than 2048 × 2048",
TooMuchToDraw => "is an SVG with more to draw than a 2048 × 2048 image",
SvgTooMuchToRead => "is an SVG whose style sheets, element attributes or entities holding tags take more to read than RustGIS allows",
SvgTooNested => "is an SVG with more than 40,000 XML nodes or nested deeper than 64 levels",
SvgUnknownRadius => "is an SVG with a radius whose size RustGIS can't know (in em or ex, or in % of a size in em or ex, or of a nested size in % over 100%)",
SvgTooSmall => "is an SVG too small to draw",
Expand Down Expand Up @@ -371,6 +376,7 @@ impl From<svg::Refusal> for MarkerRefusal {
svg::Refusal::NotSvg => MarkerRefusal::NotAnImage,
svg::Refusal::TooMuch => MarkerRefusal::TooMuchToDraw,
svg::Refusal::PastRun => MarkerRefusal::PastRunPixels,
svg::Refusal::TooMuchToRead => MarkerRefusal::SvgTooMuchToRead,
svg::Refusal::TooNested => MarkerRefusal::SvgTooNested,
svg::Refusal::UnknownRadius => MarkerRefusal::SvgUnknownRadius,
svg::Refusal::Undrawn => MarkerRefusal::SvgUndrawn,
Expand Down Expand Up @@ -776,6 +782,7 @@ mod tests {
TooManyBytes,
TooManyPixels,
TooMuchToDraw,
SvgTooMuchToRead,
SvgTooNested,
SvgUnknownRadius,
SvgTooSmall,
Expand All @@ -784,7 +791,7 @@ mod tests {
PastRunPixels
]
.map(MarkerRefusal::lasts),
[true, true, true, true, true, true, true, true, true, false]
[true, true, true, true, true, true, true, true, true, true, false]
);
// A kept image the run's spent budget refuses is kept as it is; one refused for itself
// isn't; one that draws is.
Expand Down Expand Up @@ -903,6 +910,8 @@ mod tests {
(long_png, TooManyBytes),
(svg(&deep), SvgTooNested),
(svg(&nodes), SvgTooNested),
// Its own cause (#2800), not "more to draw": 20,000 declarations in a `style` take too long to read.
(svg(&format!(r#"<rect width="1" height="1" style="{}"/>"#, "fill: red; ".repeat(20_000))), SvgTooMuchToRead),
(svg(r#"<circle r="1em"/>"#), SvgUnknownRadius),
(svg(r#"<rect width="9" height="9" rx="2ex"/>"#), SvgUnknownRadius),
// A radius in % of a size in em or ex with no view box, or of a nested one past 100%.
Expand Down
Loading
Loading