Page MenuHome

SVG importer crashing with a simple, large file from Inkscape 0.48
Closed, ResolvedPublic

Description

System Information
Ubuntu 13.10, NVIDIA Quadro 1000M

Blender Version
Broken: 2.69.0 r60991

Short description of error

While trying to import a very simple but large svg file I prepared (

), Blender crashes.
The svg was originally generated in the browser with d3.js, then saved, read into inkscape 0.48, and from there exported as Plain SVG.
It contains some ~30 graphs (no fill, black stroke) , the markup is dead simple and can be easily read with a text editor.

The crash occurs still inside the python import script, this is the traceback:

Traceback (most recent call last):
  File "/opt/blender_downloaded/2.69/scripts/addons/io_curve_svg/__init__.py", line 61, in execute
    **self.as_keywords(ignore=("filter_glob",)))
  File "/opt/blender_downloaded/2.69/scripts/addons/io_curve_svg/import_svg.py", line 1851, in load
    load_svg(filepath)
  File "/opt/blender_downloaded/2.69/scripts/addons/io_curve_svg/import_svg.py", line 1843, in load_svg
    loader.createGeom(False)
  File "/opt/blender_downloaded/2.69/scripts/addons/io_curve_svg/import_svg.py", line 1077, in createGeom
    self._doCreateGeom(instancing)
  File "/opt/blender_downloaded/2.69/scripts/addons/io_curve_svg/import_svg.py", line 1129, in _doCreateGeom
    geom.createGeom(instancing)
  File "/opt/blender_downloaded/2.69/scripts/addons/io_curve_svg/import_svg.py", line 1077, in createGeom
    self._doCreateGeom(instancing)
  File "/opt/blender_downloaded/2.69/scripts/addons/io_curve_svg/import_svg.py", line 1755, in _doCreateGeom
    super()._doCreateGeom(False)
  File "/opt/blender_downloaded/2.69/scripts/addons/io_curve_svg/import_svg.py", line 1129, in _doCreateGeom
    geom.createGeom(instancing)
  File "/opt/blender_downloaded/2.69/scripts/addons/io_curve_svg/import_svg.py", line 1077, in createGeom
    self._doCreateGeom(instancing)


File "/opt/blender_downloaded/2.69/scripts/addons/io_curve_svg/import_svg.py", line 1200, in _doCreateGeom
  bezt = act_spline.bezier_points[-1]
IndexError: bpy_prop_collection[-1]: out of range.

Exact steps for others to reproduce the error

  1. Download and save on your disk
  2. Open blender (e.g. w/ startup file)
  3. Go to File > Import > Scalable Vector Graphics (.svg)
  4. Find and choose the previously downloaded file
  5. Blender freezes for a few seconds and then crashes

Event Timeline

Simon Repp (simonrepp) raised the priority of this task from to Needs Triage by Developer.
Simon Repp (simonrepp) updated the task description. (Show Details)
Simon Repp (simonrepp) set Type to Bug.

I'll look a bit into it, feel free to beat me to it in case you're familiar with the code and able to provide a fast fix.
Especially let me know if you think my svg file is the actual problem here ... Not that I created anything fancy there, but you never know ... :)

Thought i'd run the file through http://validator.w3.org ... and it validates.
That makes it less likely an Inkscape related problem, i guess.
Back to reading code ...

So the error occurs when the importer generates the geometry inside blender. (That is, after parsing, which seems to work fine)
Inside class SVGGeometryPATH an object (curve) is created, a bezier spline is added to it, then the script starts adding bezier points, copying over the coordinates from the parsed data.
When printing the spline's bezier_points array length it becomes apparent that the error occurs right when an overflow happens:

len(act_spline.bezier_points)

...

32764
32765
32766
32767 (= signed 16 bit int range upper border)
-32768 (= signed 16 bit int range lower border)

So now the question is: Is this by design?

If Blender internally only allows splines with a maximum of 32767 points - and intentionally so - then this is not really a bug of the importer, but rather a shortcoming in gracefully handling this case and reporting that Blender does not support curves with that many points. If on the other hand, we would actually want Blender to be able to handle such an amount of spline data, we probably have to dig deeper and fix how (or in other words: with which type) the bezier points are allocated internally.

I hope my assessment of the situation is correct and I didn't overlook something else.
In any case, I would now need feedback to continue. TIA :)

Here's two little python snippets for triggering the issue directly from the console:

Create Curve (= 2 points) and add 32765 points = 32767 points - works

bpy.ops.curve.primitive_bezier_curve_add()
bpy.data.objects['BezierCurve'].data.splines[0].bezier_points.add(count=32765)

Create Curve (= 2 points) and add 32766 points = 32768 points - crashes

bpy.ops.curve.primitive_bezier_curve_add()
bpy.data.objects['BezierCurve'].data.splines[0].bezier_points.add(count=32766)

It seems reasonable to me to bump some members in the curve data structures like pntsu from short to int, since this seems quite low. But you'd need to carefully check all the files where such member variables are used, since they may still be assigned to shorts in some computations.

Brecht Van Lommel (brecht) lowered the priority of this task from Needs Triage by Developer to Confirmed, Medium.Jan 13 2014, 10:25 PM
Simon Repp (simonrepp) edited this Maniphest Task.Jan 14 2014, 3:22 PM