scour-project / scour

Scour - An SVG Optimizer / Cleaner
Apache License 2.0
757 stars 61 forks source link

RecursionError: maximum recursion depth exceeded #310

Open kno10 opened 1 year ago

kno10 commented 1 year ago

This SVG image crashes scour with a recursion depth error (debian package version 0.38.2): test

Traceback (most recent call last):
  File "/usr/bin/scour", line 33, in <module>
    sys.exit(load_entry_point('scour==0.38.2', 'console_scripts', 'scour')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/scour/scour.py", line 4220, in run
    start(options, input, output)
  File "/usr/lib/python3/dist-packages/scour/scour.py", line 4188, in start
    out_string = scourString(in_string, options).encode("UTF-8")
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/scour/scour.py", line 3761, in scourString
    _num_style_properties_fixed = repairStyle(doc.documentElement, options)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/scour/scour.py", line 1815, in repairStyle
    num += repairStyle(child, options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/scour/scour.py", line 1815, in repairStyle
    num += repairStyle(child, options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/scour/scour.py", line 1815, in repairStyle
    num += repairStyle(child, options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  [Previous line repeated 494 more times]
  File "/usr/lib/python3/dist-packages/scour/scour.py", line 1725, in repairStyle
    if styleInheritedFromParent(node, 'stroke') in [None, 'none']:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/scour/scour.py", line 1846, in styleInheritedFromParent
    return styleInheritedFromParent(parentNode, style)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/scour/scour.py", line 1846, in styleInheritedFromParent
    return styleInheritedFromParent(parentNode, style)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/scour/scour.py", line 1846, in styleInheritedFromParent
    return styleInheritedFromParent(parentNode, style)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  [Previous line repeated 493 more times]
  File "/usr/lib/python3/dist-packages/scour/scour.py", line 1834, in styleInheritedFromParent
    styles = _getStyle(parentNode)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/scour/scour.py", line 1663, in _getStyle
    style_attribute = node.getAttribute('style')
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded

The image was generated with matplotlib, then converted to SVG with inkscape. It seems that inkscape managed to stack 500 <g> elements in one another... it does not happen with pdfcairo, nor pdf2svg, nor inkscape --pdf-poppler.