From 43ab04fe3c96036907e088ff2538661f58074b61 Mon Sep 17 00:00:00 2001 From: Stefan <96178532+stefan6419846@users.noreply.github.com> Date: Fri, 24 Nov 2023 14:22:53 +0100 Subject: [PATCH 1/3] BUG: Handle indirect objects as parameters for CCITTFaxDecode --- pypdf/filters.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pypdf/filters.py b/pypdf/filters.py index b6d198f55..70d543cb8 100644 --- a/pypdf/filters.py +++ b/pypdf/filters.py @@ -564,6 +564,8 @@ def _get_parameters( k = 0 columns = 1728 if parameters: + if isinstance(parameters, IndirectObject): + parameters = parameters.get_object() if isinstance(parameters, ArrayObject): for decode_parm in parameters: if CCITT.COLUMNS in decode_parm: From 225cfebd3e103147506449b40603c9e944bdb3aa Mon Sep 17 00:00:00 2001 From: Stefan <96178532+stefan6419846@users.noreply.github.com> Date: Sat, 25 Nov 2023 09:19:54 +0100 Subject: [PATCH 2/3] add type hint and drop condition --- pypdf/filters.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pypdf/filters.py b/pypdf/filters.py index 70d543cb8..f47521f82 100644 --- a/pypdf/filters.py +++ b/pypdf/filters.py @@ -558,14 +558,13 @@ class CCITTFaxDecode: @staticmethod def _get_parameters( - parameters: Union[None, ArrayObject, DictionaryObject], rows: int + parameters: Union[None, ArrayObject, DictionaryObject, IndirectObject], rows: int ) -> CCITParameters: # TABLE 3.9 Optional parameters for the CCITTFaxDecode filter k = 0 columns = 1728 if parameters: - if isinstance(parameters, IndirectObject): - parameters = parameters.get_object() + parameters = parameters.get_object() if isinstance(parameters, ArrayObject): for decode_parm in parameters: if CCITT.COLUMNS in decode_parm: From 62ba6e4f8beb7cc5420fb0657d6236439aac4a20 Mon Sep 17 00:00:00 2001 From: Stefan <96178532+stefan6419846@users.noreply.github.com> Date: Sat, 25 Nov 2023 09:25:03 +0100 Subject: [PATCH 3/3] fix type issues --- pypdf/filters.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pypdf/filters.py b/pypdf/filters.py index f47521f82..471c78ae9 100644 --- a/pypdf/filters.py +++ b/pypdf/filters.py @@ -564,18 +564,18 @@ def _get_parameters( k = 0 columns = 1728 if parameters: - parameters = parameters.get_object() - if isinstance(parameters, ArrayObject): - for decode_parm in parameters: + parameters_unwrapped = cast(Union[ArrayObject, DictionaryObject], parameters.get_object()) + if isinstance(parameters_unwrapped, ArrayObject): + for decode_parm in parameters_unwrapped: if CCITT.COLUMNS in decode_parm: columns = decode_parm[CCITT.COLUMNS] if CCITT.K in decode_parm: k = decode_parm[CCITT.K] else: - if CCITT.COLUMNS in parameters: - columns = parameters[CCITT.COLUMNS] # type: ignore - if CCITT.K in parameters: - k = parameters[CCITT.K] # type: ignore + if CCITT.COLUMNS in parameters_unwrapped: + columns = parameters_unwrapped[CCITT.COLUMNS] # type: ignore + if CCITT.K in parameters_unwrapped: + k = parameters_unwrapped[CCITT.K] # type: ignore return CCITParameters(k, columns, rows)