Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d948faf

Browse filesBrowse files
committed
Merge pull request #5515 from mdboom/png-fishiness
Fix some theoretical problems with png reading
2 parents 0834f7e + d7d7038 commit d948faf
Copy full SHA for d948faf

File tree

Expand file treeCollapse file tree

3 files changed

+9
-6
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+9
-6
lines changed

‎lib/matplotlib/backends/backend_agg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_agg.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ def print_png(self, filename_or_obj, *args, **kwargs):
526526
close = True
527527
else:
528528
close = False
529+
529530
try:
530531
_png.write_png(renderer._renderer, filename_or_obj, self.figure.dpi)
531532
finally:

‎lib/matplotlib/image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,8 @@ def pilread(fname):
12791279
from PIL import Image
12801280
except ImportError:
12811281
return None
1282-
image = Image.open(fname)
1283-
return pil_to_array(image)
1282+
with Image.open(fname) as image:
1283+
return pil_to_array(image)
12841284

12851285
handlers = {'png': _png.read_png, }
12861286
if format is None:

‎src/_png.cpp

Copy file name to clipboardExpand all lines: src/_png.cpp
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,12 @@ static void _read_png_data(PyObject *py_file_obj, png_bytep data, png_size_t len
328328
Py_ssize_t bufflen;
329329
if (read_method) {
330330
result = PyObject_CallFunction(read_method, (char *)"i", length);
331-
}
332-
if (PyBytes_AsStringAndSize(result, &buffer, &bufflen) == 0) {
333-
if (bufflen == (Py_ssize_t)length) {
334-
memcpy(data, buffer, length);
331+
if (PyBytes_AsStringAndSize(result, &buffer, &bufflen) == 0) {
332+
if (bufflen == (Py_ssize_t)length) {
333+
memcpy(data, buffer, length);
334+
} else {
335+
PyErr_SetString(PyExc_IOError, "read past end of file");
336+
}
335337
}
336338
}
337339
Py_XDECREF(read_method);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.