5.1.0-1ubuntu0.6 on bionic (python2) can fail on Parser.feed(data) due to OSError
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
pillow (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
The python2 version of pillow in bionic (python-pil 5.1.0-1ubuntu0.6) included debian/
```
--- a/src/PIL/
+++ b/src/PIL/
@@ -522,12 +522,18 @@ def _safe_read(fp, size):
:param fp: File handle. Must implement a <b>read</b> method.
:param size: Number of bytes to read.
- :returns: A string containing up to <i>size</i> bytes of data.
+ :returns: A string containing <i>size</i> bytes of data.
+
+ Raises an OSError if the file is truncated and the read can not be completed
+
"""
if size <= 0:
return b""
if size <= SAFEBLOCK:
- return fp.read(size)
+ data = fp.read(size)
+ if len(data) < size:
+ raise OSError("Truncated File Read")
+ return data
data = []
while size > 0:
block = fp.read(min(size, SAFEBLOCK))
@@ -535,6 +541,8 @@ def _safe_read(fp, size):
break
size -= len(block)
+ if sum(len(d) for d in data) < size:
+ raise OSError("Truncated File Read")
return b"".join(data)
```
However, further up in the file in the `feed` method we have:
```
# attempt to open this file
try:
with io.BytesIO(
im = Image.open(fp)
except IOError:
# traceback.
pass # not enough data
```
In the python3 version of this file the IOError has already been changed to OSError but not so here.
In my local copy of /usr/lib/
I've tried running the test suite locally (with `make test`) to submit a patch, but I'm getting lots of unrelated failures in tests (missing pytest imports, file comparisons not matching, etc.). Happy to provide more detail on that if appropriate.
Status changed to 'Confirmed' because the bug affects multiple users.