-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Will hang on invalid PDFs #77
Comments
Certainly we would be open to such patches. PyPDF2 will often hang on unexpected input (such as variations in syntax), where it should instead throw a proper exception and/or handle the data in the best way possible. Your proposed plan would definitely help to improve PyPDF2. |
:D awesome. I've got a bit of a crunch at work coming up, but I'll take a look afterwards. |
I usually wrap processing of a document with PyPDF into some type of timer. class TimeOutAlarm(Exception):
pass
def timeout_alarm_handler(signum, frame):
raise TimeOutAlarm
class RotationTimeOutException(Exception):
pass
signal.signal(signal.SIGALRM, timeout_alarm_handler)
signal.alarm(15)
reader = PdfFileReader(rfile, strict=False, )
writer = PdfFileWriter()
for pagenum in range(reader.numPages):
try:
signal.alarm(15)
page = reader.getPage(pagenum)
if not counter_clockwise:
page.rotateClockwise(rotate_degrees)
else:
page.rotateCounterClockwise(rotate_degrees)
page.compressContentStreams()
writer.addPage(page)
signal.alarm(0)
page = None
except TimeOutAlarm:
raise RotationTimeOutException
else:
writer.write(wfile)
writer = None |
Does anybody have a PDF showing this issue? |
If anybody runs into this issue again, please let me know. I close this for the moment. |
Doing some testing, I noticed that PyPDF2 will hang if it encounters an invalid PDF… for example, the
skipOverComment
function:Will hang indefinitely.
I would propose three courses of action:
Add a script for automating fuzz testing to the repo
Fix the bugs as the script from step (2) finds them
What do you think? Would you be open to patches for those?
The text was updated successfully, but these errors were encountered: