Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer overflow in xkcd example with pdf backend. #4230

Closed
jenshnielsen opened this issue Mar 16, 2015 · 3 comments
Closed

Buffer overflow in xkcd example with pdf backend. #4230

jenshnielsen opened this issue Mar 16, 2015 · 3 comments
Assignees
Milestone

Comments

@jenshnielsen
Copy link
Member

I am seeing a buffer overflow bug when building the docs with pdf files in the XKCD example.

import matplotlib.pyplot as plt
import numpy as np

with plt.xkcd():
    # Based on "The Data So Far" from XKCD by Randall Monroe
    # http://xkcd.com/373/

    fig = plt.figure()
    ax = fig.add_axes((0.1, 0.2, 0.8, 0.7))
    ax.bar([-0.125, 1.0 - 0.125], [0, 100], 0.25)
    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')
    ax.xaxis.set_ticks_position('bottom')
    ax.set_xticks([0, 1])
    ax.set_xlim([-0.5, 1.5])
    ax.set_ylim([0, 110])
    ax.set_xticklabels(['CONFIRMED BY\nEXPERIMENT', 'REFUTED BY\nEXPERIMENT'])
    plt.yticks([])

    plt.title("CLAIMS OF SUPERNATURAL POWERS")

    fig.text(
        0.5, 0.05,
        '"The Data So Far" from xkcd by Randall Monroe',
        ha='center')
    plt.savefig('test.pdf')

Results in:

Traceback (most recent call last):
  File "xkcd.py", line 26, in <module>
    plt.savefig('test.pdf')
  File "/Users/jhn/Envs/mplstable/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.10-x86_64.egg/matplotlib/pyplot.py", line 576, in savefig
    res = fig.savefig(*args, **kwargs)
  File "/Users/jhn/Envs/mplstable/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.10-x86_64.egg/matplotlib/figure.py", line 1490, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/Users/jhn/Envs/mplstable/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.10-x86_64.egg/matplotlib/backend_bases.py", line 2213, in print_figure
    **kwargs)
  File "/Users/jhn/Envs/mplstable/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.10-x86_64.egg/matplotlib/backends/backend_pdf.py", line 2509, in print_pdf
    self.figure.draw(renderer)
  File "/Users/jhn/Envs/mplstable/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.10-x86_64.egg/matplotlib/artist.py", line 60, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Users/jhn/Envs/mplstable/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.10-x86_64.egg/matplotlib/figure.py", line 1032, in draw
    self.patch.draw(renderer)
  File "/Users/jhn/Envs/mplstable/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.10-x86_64.egg/matplotlib/artist.py", line 60, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Users/jhn/Envs/mplstable/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.10-x86_64.egg/matplotlib/patches.py", line 484, in draw
    renderer.draw_path(gc, tpath, affine, rgbFace)
  File "/Users/jhn/Envs/mplstable/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.10-x86_64.egg/matplotlib/patheffects.py", line 107, in draw_path
    rgbFace)
  File "/Users/jhn/Envs/mplstable/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.10-x86_64.egg/matplotlib/patheffects.py", line 208, in draw_path
    Stroke.draw_path(self, renderer, gc, tpath, affine, rgbFace)
  File "/Users/jhn/Envs/mplstable/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.10-x86_64.egg/matplotlib/patheffects.py", line 197, in draw_path
    renderer.draw_path(gc0, tpath, trans, rgbFace)
  File "/Users/jhn/Envs/mplstable/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.10-x86_64.egg/matplotlib/backends/backend_pdf.py", line 1611, in draw_path
    gc.get_sketch_params())
  File "/Users/jhn/Envs/mplstable/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.10-x86_64.egg/matplotlib/backends/backend_pdf.py", line 1416, in writePath
    sketch=sketch)
  File "/Users/jhn/Envs/mplstable/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.10-x86_64.egg/matplotlib/backends/backend_pdf.py", line 1406, in pathOperations
    True))]
MemoryError: Buffer overflow

I have bisected this down to the merge of #4197 specifically cc41bff

@tacaswell tacaswell added this to the next point release milestone Mar 16, 2015
@tacaswell
Copy link
Member

I'm thinking this is the 'correct' behavior and the buffer just needs to be bigger.

@jenshnielsen
Copy link
Member Author

Sounds plausible. I have not yet had a chance to dig into that code but it makes sense that a larger buffer is needed for xkcd plots

@mdboom
Copy link
Member

mdboom commented Mar 16, 2015

Doh. That's right. I'll work on a solution.

@mdboom mdboom self-assigned this Mar 16, 2015
@mdboom mdboom closed this as completed in bd837a0 Mar 17, 2015
tacaswell added a commit that referenced this issue Mar 17, 2015
Fix : Don't overflow buffer with sketch path.

Closes #4230
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants