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

1.5rc1: Calling figure transform with wrong argument crashs python #5105

Closed
Tillsten opened this issue Sep 19, 2015 · 9 comments · Fixed by #5168
Closed

1.5rc1: Calling figure transform with wrong argument crashs python #5105

Tillsten opened this issue Sep 19, 2015 · 9 comments · Fixed by #5168
Assignees
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. status: confirmed bug
Milestone

Comments

@Tillsten
Copy link
Contributor

Following lead to a interpreter crash:

import matplotlib.pyplot as plt
fig = plt.figure()
#Just just give an exception
fig.transFigure.transform(1)

Windows 10, 64 bit, 2.7

@tacaswell tacaswell added this to the next point release (1.5.0) milestone Sep 19, 2015
@tacaswell tacaswell added status: confirmed bug Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. labels Sep 19, 2015
@tacaswell
Copy link
Member

Segfaults on linux as well.

That is exciting!

attn @mdboom

@cgohlke
Copy link
Contributor

cgohlke commented Sep 20, 2015

The crash is at https://github.com/matplotlib/matplotlib/blob/master/src/numpy_cpp.h#L471, when m_shape==NULL.

This does not crash:

diff --git a/src/numpy_cpp.h b/src/numpy_cpp.h
index 10ae68c..c961e25 100644
--- a/src/numpy_cpp.h
+++ b/src/numpy_cpp.h
@@ -465,7 +465,7 @@ class array_view : public detail::array_view_accessors<array_view, T, ND>

     npy_intp dim(size_t i) const
     {
-        if (i > ND) {
+        if ((i > ND) || (m_shape == NULL)) {
             return 0;
         }
         return m_shape[i];

@jkseppan
Copy link
Member

I don't think array_view is supposed to have m_shape == NULL. The code tries to assign a zeros array to m_shape when the view is uninitialized. I suspect one of the constructors is not doing sufficient checking of numpy return values.

@jkseppan
Copy link
Member

The zero-data branch sets m_shape correctly but then falls through to the code below, which sets m_shape to the return value of PyArray_DIMS, which seems to be NULL for numpy scalars. I'm working on a patch.

@jkseppan
Copy link
Member

Patch in #5106.

@cgohlke
Copy link
Contributor

cgohlke commented Oct 2, 2015

Even if m_shape != NULL shouldn't the dim function read if (i >= ND) { instead of if (i > ND) {?

@jkseppan
Copy link
Member

jkseppan commented Oct 2, 2015

@cgohlke is right, that looks like a bug even if it wasn't the cause of this crash.

@jkseppan jkseppan reopened this Oct 2, 2015
@jkseppan
Copy link
Member

jkseppan commented Oct 2, 2015

In many cases m_shape gets initialized to zeros, which is a static array of three numbers. That looks bad too, although I imagine all uses of this class are for at most three dimensions.

@jkseppan
Copy link
Member

jkseppan commented Oct 2, 2015

Oh, I suppose since array_view_accessors is only instantiated for ND less than 4, it should be impossible to instantiate array_view<T, 4>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. status: confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants