Skip to content

Commit

Permalink
ROB: Ignore EOF in NumberObject.read_from_stream
Browse files Browse the repository at this point in the history
Use `ignore_eof=True` just like `NameObject` does, which is the only other
caller to `read_until_regex` in this module.

This helps prevent arcane exceptions when trying to parse a number:

```
PyPDF2.errors.PdfStreamError: Stream has ended unexpectedly
```

The motivation is essentially identical to the change that introduced
`ignore_eof=True` on `NameObject`s:
431ba70
  • Loading branch information
rraval committed Dec 16, 2022
1 parent c95eabf commit b4cb2fa
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion PyPDF2/generic/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def writeToStream(

@staticmethod
def read_from_stream(stream: StreamType) -> Union["NumberObject", "FloatObject"]:
num = read_until_regex(stream, NumberObject.NumberPattern)
num = read_until_regex(stream, NumberObject.NumberPattern, ignore_eof=True)
if num.find(b".") != -1:
return FloatObject(num)
return NumberObject(num)
Expand Down

0 comments on commit b4cb2fa

Please sign in to comment.