getnikola / nikola

A static website and blog generator
https://getnikola.com/
MIT License
2.6k stars 445 forks source link

"Large" SVG files can crash build #3785

Closed Xaldew closed 2 weeks ago

Xaldew commented 3 weeks ago

Environment

Python Version: Python 3.10.12

Nikola Version: Nikola v8.3.1

Operating System: Ubuntu Jammy 22.04

Description:

I'm currently working on adding some SVG images to my blog, but ran into a bit of an issue with the image processing:

nikola build
Scanning posts...........done!
.  scale_images:output/images/publications/succinct-opacity-micromaps/compression-teaser.opt.svg
TaskError - taskid:scale_images:output/images/publications/succinct-opacity-micromaps/compression-teaser.opt.svg
PythonAction Error
Traceback (most recent call last):
  File "/home/xaldew/git/homepage/venv/lib/python3.10/site-packages/doit/action.py", line 461, in execute
    returned_value = self.py_callable(*self.args, **kwargs)
  File "/home/xaldew/git/homepage/venv/lib/python3.10/site-packages/nikola/plugins/task/scale_images.py", line 69, in process_image
    self.resize_image(
  File "/home/xaldew/git/homepage/venv/lib/python3.10/site-packages/nikola/image_processing.py", line 107, in resize_image
    self.resize_svg(src, dst_paths, max_sizes, bigger_panoramas)
  File "/home/xaldew/git/homepage/venv/lib/python3.10/site-packages/nikola/image_processing.py", line 184, in resize_svg
    tree = lxml.etree.XML(xml)
  File "src/lxml/etree.pyx", line 3285, in lxml.etree.XML
  File "src/lxml/parser.pxi", line 1995, in lxml.etree._parseMemoryDocument
  File "src/lxml/parser.pxi", line 1882, in lxml.etree._parseDoc
  File "src/lxml/parser.pxi", line 1164, in lxml.etree._BaseParser._parseDoc
  File "src/lxml/parser.pxi", line 633, in lxml.etree._ParserContext._handleParseResultDoc
  File "src/lxml/parser.pxi", line 743, in lxml.etree._handleParseResult
  File "src/lxml/parser.pxi", line 672, in lxml.etree._raiseParseError
  File "<string>", line 42
lxml.etree.XMLSyntaxError: Memory allocation failed : Huge input lookup, line 42, column 10000034

########################################
scale_images:output/images/publications/succinct-opacity-micromaps/compression-teaser.opt.svg <stdout>:

Admittedly, the image is kind of large (~50MB), I assume from having several embedded 1920x1080 PNGs (Base-64 encoded, I think). However, I would argue that it's not really large enough to warrant this failure, and probably should have some kind of fallback to handle large SVGs anyways. Perhaps it should simply issue a warning and just copy the SVG when something like the above happen?

The image in question is linked here, since it's too big to include on GitHub: https://gustafwaldemarson.com/misc/compression-teaser.opt.svg