cubicsuperpath crashes on some paths

Bug #1646595 reported by Mitch Bradley
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Inkscape
In Progress
Undecided
Unassigned

Bug Description

Inkscape 0.91. When using either the gcodetools extension or the J-Tech Photonics Laser Tool extension, you often get an "index out of range" exception from CubicSuperPath, specifically line 150 of share/extensions/cubicsuperpath.py.

I think the problem occurs with paths that do not include an 'M' element. I made the problem go away by changing line 150 from:

   csp[subpath].append([lastctrl[:],last[:],last[:]])

to:

    if last:
        csp[subpath].append([lastctrl[:],last[:],last[:]])

I don't know enough about paths and superpaths to be sure this is the best possible solution, but it certainly avoids the crash, and the resulting GCode from the cited extensions is correct.

Revision history for this message
Alvin Penner (apenner) wrote :

could you attach a sample svg file for testing purposes?

Revision history for this message
Mitch Bradley (wmb-a) wrote :

Here's a very simple .svg that crashes the J-Tech Photonics Laser Tool extension.

The path was generated by the Hersey Text extension, rendering the text string "I I" in the "Sans 1-stroke" font face.

The crux of the problem appears to be path id "path42563", whose "d" attribute has the value "8" instead of a list of M's and L's. That attribute apparently resulted from the space in the string, as space-less strings do not have any funny "d" values and do not trigger the crash..

If I delete just that one funny path id (using the XML editor), the crash stops.

It might be argued that the problem is in the Hershey Text extension. However, it would seem prudent for cubicsuperpath.py to be resilient in the presence of dubious paths. In a followup comment I will post a proposed patch for hershey.py

Revision history for this message
Mitch Bradley (wmb-a) wrote :

This patch eliminates bogus path elements in Hershey Text containing spaces. Previously, when draw_svg_text() was asked to render a space, it generated a path element that contained just a number, which happened to be the character cell width, instead of a proper path starting with an "M" (moveto).

Malformed path elements can crash other extensions, such as cubicsuperpath.py.

Revision history for this message
Alvin Penner (apenner) wrote :

confirmed on Windows 10, Inkscape 0.92pre3 15195
I used the Gcodetools->Area extension and got the error message:

.......................................................

Cutting tool has not been defined! A default tool has been automatically added.

Traceback (most recent call last):

  File "gcodetools.py", line 6751, in <module>

    gcodetools.affect()

  File "C:\Program Files (x86)\Inkscape\share\extensions\inkex.py", line 283, in affect

    self.effect()

  File "gcodetools.py", line 6679, in effect

    self.area()

  File "gcodetools.py", line 4767, in area

    csp = cubicsuperpath.parsePath(d)

  File "C:\Program Files (x86)\Inkscape\share\extensions\cubicsuperpath.py", line 163, in parsePath

    return CubicSuperPath(simplepath.parsePath(d))

  File "C:\Program Files (x86)\Inkscape\share\extensions\simplepath.py", line 109, in parsePath

    raise Exception, 'Invalid path, no initial command.'

Exception: Invalid path, no initial command.

Changed in inkscape:
status: New → Confirmed
jazzynico (jazzynico)
tags: added: extensions-plugins
jazzynico (jazzynico)
Changed in inkscape:
status: Confirmed → Triaged
jazzynico (jazzynico)
Changed in inkscape:
status: Triaged → In Progress
Revision history for this message
jazzynico (jazzynico) wrote :

Could someone with some path knowledge confirm the analysis?

Changed in inkscape:
milestone: none → 0.93
Revision history for this message
Mitch Bradley (wmb-a) wrote :

After writing the initial bug report, I learned more about SVG paths.

A good doc source is https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths

According to that doc, a well-formed path always starts with an "M" (moveto) element, which provides the starting location for the path. The M is then followed by various other elements like "L" (lineto), "C" (curveto), etc. Those following elements tell where to go.

A path without an M could be one of two things.

1) The path could be empty - a null path - there is nothing at all inside the path "container". This is the situation that triggered the crash.

2) The path could be malformed - it has "lineto" or "curveto" elements without an initial M. That is meaningless because you need to know where you are before you can go somewhere. That might be okay if there were a notion of a stateful "current point" that persists from one path to the next, but SVG doesn't work that way; each path is self-contained.

Given that programming axiom that code should not crash in the face of empty input, I'm pretty sure that the patch is correct for case (1), which is the observed situation.

Ideally, the code should not crash for other forms of malformed input, for example a path that contains only a "Z" (close path) element, but that is somewhat harder to implement and perhaps a topic for later.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.