claird / PyPDF4

A utility to read and write PDFs with Python
obsolete-https://pythonhosted.org/PyPDF2/
Other
330 stars 61 forks source link

FlateDecode /Column parameter default value should be 1 #3

Closed acsor closed 6 years ago

acsor commented 6 years ago

From ISO 32000, §7.4.4.3, LZWDecode and FlateDecode Parameters, Table 8, FlateDecode.decode() seems to be supposed to define a default value for the /Columns key in the /DecodeParms dictionary.

Here is how it appeared before in PyPDF4/filters.py:121:

# predictor 1 == no predictor
        if predictor != 1:
            columns = decodeParms["/Columns"]
            # PNG prediction:
if predictor >= 10 and predictor <= 15:

And here how I intend to fix it:

        if predictor != 1:
            # The /Columns param. has 1 as the default value; see ISO 32000,
            # §7.4.4.3 LZWDecode and FlateDecode Parameters, Table 8
            columns = decodeParms.get("/Columns", 1)

            # PNG prediction:
            if 10 <= predictor <= 15:

I noticed the (small) flaw during a unit test, that is soon going to be published.

acsor commented 6 years ago

Note that the issue is noticeable only when decodeParms["/Predictor"] != 1.

acsor commented 6 years ago

This issue was solved here.