Skip to content
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

[DA-3868] - Try to decompressing data streams first #1

Merged
merged 1 commit into from
Mar 25, 2022

Conversation

Itisfilipe
Copy link

@Itisfilipe Itisfilipe commented Mar 25, 2022

This change will force zlib decompressing data streams that won’t fit into memory first and then fall back to the usual decompress method.

It is intended to fix those events https://sentry.drchrono.com/drchrono/drchrono-web/issues/245739 with the message Error -5 while decompressing data: incomplete or truncated stream and it is based on py-pdf#88

You can get a broken PDF by going to Sentry event and getting the ConsentFormSignature id from the stack trace and then under prod or staging djsp you get the signed URL for the file.

cfs = ConsentFormSignature.objects.get(pk=XXXXXX)
cf = cfs.consent_form
print cf.uri.url

Download the file to your computer and use this script to test it

from PyPDF2 import PdfFileReader, PdfFileWriter

cf = PdfFileReader("broken-pdf.pdf")

output = PdfFileWriter()

num_pages = cf.getNumPages()

for i in range(num_pages):
    output.addPage(cf.getPage(i))

output_stream = open("fixedFile3.pdf", "wb")
output.write(output_stream)
output_stream.close()

It Should blow up with this error without this change error: Error -5 while decompressing data: incomplete or truncated stream but then work with this change.

@Itisfilipe Itisfilipe merged commit 112b0ed into master Mar 25, 2022
@Itisfilipe Itisfilipe deleted the fix-error-decompress-pdf branch March 25, 2022 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants