Skip to content

Commit

Permalink
BUG: Fix zlib -5 error for corrupt files (#603)
Browse files Browse the repository at this point in the history
Closes #609
Closes #88
  • Loading branch information
thijsbrouwers committed Apr 16, 2022
1 parent 89bc093 commit 354f8ce
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion PyPDF2/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,17 @@
import zlib

def decompress(data):
return zlib.decompress(data)
try:
return zlib.decompress(data)
except zlib.error:
d = zlib.decompressobj(zlib.MAX_WBITS | 32)
result_str = b''
for b in [data[i:i + 1] for i in range(len(data))]:
try:
result_str += d.decompress(b)
except zlib.error:
pass
return result_str

def compress(data):
return zlib.compress(data)
Expand Down

0 comments on commit 354f8ce

Please sign in to comment.