Skip to content

Possibly undefined variable in FlateDecode.decode if parameters are an ArrayObject #2159

@stefan6419846

Description

@stefan6419846

When looking through the code for understanding #2158, I stumbled upon some possibly undefined variable.

Let's take the following snippet:

pypdf/pypdf/filters.py

Lines 143 to 165 in 05f2a65

if isinstance(decode_parms, ArrayObject):
columns = 1
bits_per_component = DEFAULT_BITS_PER_COMPONENT
for decode_parm in decode_parms:
if "/Columns" in decode_parm:
columns = decode_parm["/Columns"]
if LZW.BITS_PER_COMPONENT in decode_parm:
bits_per_component = decode_parm[LZW.BITS_PER_COMPONENT]
else:
columns = (
1 if decode_parms is None else decode_parms.get(LZW.COLUMNS, 1)
)
colors = 1 if decode_parms is None else decode_parms.get(LZW.COLORS, 1)
bits_per_component = (
decode_parms.get(LZW.BITS_PER_COMPONENT, DEFAULT_BITS_PER_COMPONENT)
if decode_parms
else DEFAULT_BITS_PER_COMPONENT
)
# PNG predictor can vary by row and so is the lead byte on each row
rowlength = (
math.ceil(columns * colors * bits_per_component / 8) + 1
) # number of bytes

It seems like in the first branch (lines 144 to 150), colors will never be defined, thus possibly leading to a crash at line 164 if I did not miss something. (I do not have any PDF file for this, as I just stumbled upon this by accident.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions