Skip to content

Commit

Permalink
fix: support arbitrary width integers (fixes: pdfminer#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdaines committed Aug 1, 2024
1 parent 1a8bd2f commit 267ac8f
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions pdfminer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 267ac8f

Please sign in to comment.