Skip to content

SVG picture markers: a large style sheet takes tens of seconds to read #2800

Done

Description

@jgregoriorincon

Before you start

  • I searched the existing issues and did not find a duplicate.
  • This is a bug report, not a usage question.

What happened?

An SVG marker image (#2266, #2704) with a large <style> sheet, or a style attribute with many declarations, keeps the command that sets it busy for many seconds, and the app with it. The SVG's bounds (crates/render/src/picture/svg.rs) don't cover it, because the time goes into parsing the sheet itself, before any count.

usvg parses style sheets and style attributes with simplecss 0.2.2. Each declaration's value ends with an identifier read that fails (consume_term, lib.rs:550). That error works out its row and column by scanning the text from the start (Stream::gen_text_pos_from, stream.rs:199, and calc_curr_row, stream.rs:281), so each declaration costs as much as its position, and a sheet costs the square of its declarations. Measured, in a dev build with dependencies at opt-level 2:

Sheet Bytes Time
10,000 rules .cN { fill: red } 199 KB 0.64 s
20,000 rules 409 KB 2.5 s
40,000 rules 829 KB 10.5 s
one rule of 20,000 declarations 220 KB 1.4 s
a 400 KB comment and one rule 400 KB 0.4 ms

A marker image may hold up to 1.5 MiB of SVG, about 75,000 such rules: some 37 s at this rate.

Steps to reproduce

  1. Make an SVG whose <style> holds 40,000 rules (.c0 { fill: red } .c1 { fill: red } …) and one <rect>.
  2. Run layer.marker {"layer": "Cities", "image": "<the SVG as base64>"} in the Script pane, on the World Atlas sample.

Expected behavior

An SVG whose style sheets take too long to read is refused quickly, like one with too much to draw (#2713), and never reaches the reader. For example, refuse a sheet or style attribute whose declarations times its length passes a cap measured at about 15 ms, before usvg reads it.

How are you running RustGIS?

Built from source (desktop).

Version

main at 519ad84.

Operating system, browser and graphics

Linux (Fedora), headless test run.

Sample data

The steps above build it.

Screenshots or logs

Found while measuring #2713 (part of #2266).

Activity

  1. jgregoriorincon commented on Nov 26, 2026

    @jgregoriorincon
    ContributorAuthor

    Taking this one: the fix is in #3030, two bounds checked before simplecss and roxmltree read the SVG (style text and element attributes), refused with their own cause in the marker notice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions