From c216b97ff41370392a65b743bb69d7bbd5563c66 Mon Sep 17 00:00:00 2001 From: pubpub-zz <4083478+pubpub-zz@users.noreply.github.com> Date: Tue, 27 Sep 2022 23:19:00 +0200 Subject: [PATCH] FIX : cope with cmap from #1322 fixes #1322 cope with cmap where the range contains first and last code are on variable length. Also fix cases where the code is on 3 characters only (not standard) no test data available --- PyPDF2/_cmap.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/PyPDF2/_cmap.py b/PyPDF2/_cmap.py index 6f0d82667..2a9e2f0d2 100644 --- a/PyPDF2/_cmap.py +++ b/PyPDF2/_cmap.py @@ -1,5 +1,6 @@ import warnings from binascii import unhexlify +from math import ceil from typing import Any, Dict, List, Tuple, Union, cast from ._codecs import adobe_glyphs, charset_encoding @@ -267,9 +268,9 @@ def parse_bfrange( ) -> Union[None, Tuple[int, int]]: lst = [x for x in l.split(b" ") if x] closure_found = False - nbi = len(lst[0]) - map_dict[-1] = nbi // 2 - fmt = b"%%0%dX" % nbi + nbi = max(len(lst[0]), len(lst[1])) + map_dict[-1] = ceil(nbi / 2) + fmt = b"%%0%dX" % (map_dict[-1] * 2) if multiline_rg is not None: a = multiline_rg[0] # a, b not in the current line b = multiline_rg[1]