From 267ac8f767e1ec0ffc46b6614a47a1482b02d7d2 Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Thu, 1 Aug 2024 09:43:27 -0400 Subject: [PATCH] fix: support arbitrary width integers (fixes: #886) --- pdfminer/utils.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/pdfminer/utils.py b/pdfminer/utils.py index a5b53852..672cc73d 100644 --- a/pdfminer/utils.py +++ b/pdfminer/utils.py @@ -359,22 +359,12 @@ def choplist(n: int, seq: Iterable[_T]) -> Iterator[Tuple[_T, ...]]: def nunpack(s: bytes, default: int = 0) -> int: - """Unpacks 1 to 4 or 8 byte integers (big endian).""" + """Unpacks variable-length integers (big endian).""" length = len(s) if not length: return default - elif length == 1: - return ord(s) - elif length == 2: - return cast(int, struct.unpack(">H", s)[0]) - elif length == 3: - return cast(int, struct.unpack(">L", b"\x00" + s)[0]) - elif length == 4: - return cast(int, struct.unpack(">L", s)[0]) - elif length == 8: - return cast(int, struct.unpack(">Q", s)[0]) else: - raise PDFTypeError("invalid length: %d" % length) + return int.from_bytes(s, "big") PDFDocEncoding = "".join(