empira / PDFsharp

PDFsharp and MigraDoc Foundation for .NET 6 and .NET Framework
https://docs.pdfsharp.net/
Other
504 stars 124 forks source link

System.InvalidOperationException: 'Stream cannot be read. Please send us the PDF file so that we can fix this (issues (at) pdfsharp.net).' #148

Open robrechtD opened 2 months ago

robrechtD commented 2 months ago

Opening a pdf from a stream produces the following exception:

System.InvalidOperationException: 'Stream cannot be read. Please send us the PDF file so that we can fix this (issues (at) pdfsharp.net).' I've attached a project to reproduce the issue.

PDFsharp.IssueSubmissionTemplate.zip

ThomasHoevel commented 2 months ago

Thanks for the feedback. The PDF file is corrupted in object 14 0. The object has an empty stream, but the length is given as 2338 bytes and that's more bytes than there are remaining in the file.

14 0 obj
<</Length 2338
/Type
/Metadata
/Subtype 
/XML>>
stream
endstream

We try to improve PDFsharp with respect to reading corrupted files, but I cannot say if or when a workaround for that corruption will come.

packdat commented 2 months ago

@ThomasHoevel I just added a commit to #152 that handles this situation.