Skip to content

Fix some theoretical problems with png reading #5515

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

Merged
merged 2 commits into from
Nov 20, 2015

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Nov 19, 2015

Possible fix fo #5495, but honestly quite theoretical.

@mdboom mdboom added this to the Critical bugfix release (1.5.1) milestone Nov 19, 2015
@WeatherGod
Copy link
Member

So, if for some reason the read method isn't there (I can't think of a reason why), how does the caller know that something went wrong?

@mdboom
Copy link
Member Author

mdboom commented Nov 20, 2015

There's no way to report an error back from a PNG reading callback. However, when the PNG reading is finished, we check PyErr_Occurred() and send the exception back to the caller.

https://github.com/matplotlib/matplotlib/blob/master/src/_png.cpp#L576

In this case, the user would get an AttributeError with whatever message PyObject_CallFunction set.

if (PyBytes_AsStringAndSize(result, &buffer, &bufflen) == 0) {
if (bufflen == (Py_ssize_t)length) {
memcpy(data, buffer, length);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see that now. Now, what if bufflen does not end up being the same as length? Are we assuming that an error has been set? Would it make sense for us to set an error if one hasn't been set?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. We should probably set an exception in that case. It basically means that it read past the end of the file (which could happen if the file were truncated or something).

tacaswell added a commit that referenced this pull request Nov 20, 2015
Fix some theoretical problems with png reading
@tacaswell tacaswell merged commit d948faf into matplotlib:master Nov 20, 2015
tacaswell added a commit that referenced this pull request Nov 20, 2015
Fix some theoretical problems with png reading
@tacaswell
Copy link
Member

back ported to v2.0.x as 3814c77

@QuLogic
Copy link
Member

QuLogic commented Nov 20, 2015

Not 1.5.x (as milestoned)?

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

Successfully merging this pull request may close these issues.

4 participants