Skip to content

Commit

Permalink
BUG: Fix stream truncated prematurely (#1223)
Browse files Browse the repository at this point in the history
Observed in case of  \0 - \9 in streams

Closes  #454
  • Loading branch information
pubpub-zz committed Aug 11, 2022
1 parent 2df8a4c commit 658bf28
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions PyPDF2/generic.py
Expand Up @@ -492,6 +492,7 @@ def read_string_from_stream(
if ntok.isdigit():
tok += ntok
else:
stream.seek(-1, 1) # ntok has to be analysed
break
tok = b_(chr(int(tok, base=8)))
elif tok in b"\n\r":
Expand Down
7 changes: 6 additions & 1 deletion tests/test_generic.py
Expand Up @@ -157,7 +157,12 @@ def test_readStringFromStream_multichar_eol2():

def test_readStringFromStream_excape_digit():
stream = BytesIO(b"x\\1a )")
assert read_string_from_stream(stream) == "\x01 "
assert read_string_from_stream(stream) == "\x01a "


def test_readStringFromStream_excape_digit2():
stream = BytesIO(b"(hello \\1\\2\\3\\4)")
assert read_string_from_stream(stream) == "hello \x01\x02\x03\x04"


def test_NameObject():
Expand Down

0 comments on commit 658bf28

Please sign in to comment.