deeplook / svglib

Read SVG files and convert them to other formats.
GNU Lesser General Public License v3.0
315 stars 80 forks source link

crash with firefox logo on svglib 0.9.1, but works on 0.9.0 #195

Closed Akuli closed 5 years ago

Akuli commented 5 years ago

Download https://upload.wikimedia.org/wikipedia/commons/6/67/Firefox_Logo%2C_2017.svg to firefox.svg

After pip install svglib==0.9.0 running this produces out.gif as expected, but after installing 0.9.1 it raises an error

from svglib import svglib
from reportlab.graphics.renderPM import drawToPIL, drawToFile

rlg = svglib.svg2rlg('firefox.svg')
drawToFile(rlg, 'out.gif')

Here is the error

Can't handle color: url(#radial-gradient)
Can't handle color: url(#radial-gradient-2)
Can't handle color: url(#linear-gradient)
Can't handle color: url(#radial-gradient-3)
Can't handle color: url(#radial-gradient-4)
Can't handle color: url(#radial-gradient-5)
Can't handle color: url(#radial-gradient-6)
Can't handle color: url(#radial-gradient-7)
Can't handle color: url(#linear-gradient-2)
Can't handle color: url(#linear-gradient-3)
Can't handle color: url(#linear-gradient-4)
Can't handle color: url(#linear-gradient-5)
Can't handle color: url(#linear-gradient-6)
Can't handle color: url(#linear-gradient-7)
Traceback (most recent call last):
  File "asdf.py", line 6, in <module>
    drawToFile(rlg, 'out.gif')
  File "/home/akuli/.local/lib/python3.5/site-packages/reportlab/graphics/renderPM.py", line 680, in drawToFile
    c = drawToPMCanvas(d, dpi=dpi, bg=bg, configPIL=configPIL, showBoundary=showBoundary)
  File "/home/akuli/.local/lib/python3.5/site-packages/reportlab/graphics/renderPM.py", line 666, in drawToPMCanvas
    draw(d, c, 0, 0, showBoundary=showBoundary)
  File "/home/akuli/.local/lib/python3.5/site-packages/reportlab/graphics/renderPM.py", line 51, in draw
    R.draw(renderScaledDrawing(drawing), canvas, x, y, showBoundary=showBoundary)
  File "/home/akuli/.local/lib/python3.5/site-packages/reportlab/graphics/renderbase.py", line 205, in draw
    self.drawNode(drawing)
  File "/home/akuli/.local/lib/python3.5/site-packages/reportlab/graphics/renderPM.py", line 108, in drawNode
    self.drawNodeDispatcher(node)
  File "/home/akuli/.local/lib/python3.5/site-packages/reportlab/graphics/renderbase.py", line 286, in drawNodeDispatcher
    self.drawGroup(node)
  File "/home/akuli/.local/lib/python3.5/site-packages/reportlab/graphics/renderbase.py", line 317, in drawGroup
    self.drawNode(node)
  File "/home/akuli/.local/lib/python3.5/site-packages/reportlab/graphics/renderPM.py", line 111, in drawNode
    self.pop()
  File "/home/akuli/.local/lib/python3.5/site-packages/reportlab/graphics/renderPM.py", line 60, in pop
    self._tracker.pop()
  File "/home/akuli/.local/lib/python3.5/site-packages/reportlab/graphics/renderbase.py", line 112, in pop
    reverseDelta[key] = inverse(lastDelta['transform'])
  File "/home/akuli/.local/lib/python3.5/site-packages/reportlab/graphics/renderbase.py", line 16, in inverse
    R = [A[3]/det, -A[1]/det, -A[2]/det, A[0]/det]
ZeroDivisionError: float division by zero
claudep commented 5 years ago

Thanks for the report, I'm almost certain the problem is in 918415335, where the condition if r != 0 is probably missing before the new introduced line. @ajbrock, maybe you could have a look?

ajbrock commented 5 years ago

I think I agree that adding if r!=0 before computing r = 1 / r -1 is a good idea to prevent divide by zero, but I'm not sure I see the error path that would lead to the divide-by-zero in reportlab. If the line in question were computing "1/0 -1" then wouldn't it be outputting an inf or a nan to reportlab? It looks like reportlab is dealing with a transform whose determinant is zero. I don't quite follow the trace logic from the ellipse code to reportlab though, so please feel free to enlighten me =)

claudep commented 5 years ago

Sorry for wrongly accusing the commit 9184153 for that regression. In fact, the problem arises after 82860fa54f8a2b.

claudep commented 5 years ago

@Akuli with 0.9.0 do you obtain anything else than a blank page?

Akuli commented 5 years ago

I seem to be getting blank page only with 0.9.0 so I think this is a good as it ever was, lol