empira / PDFsharp

PDFsharp and MigraDoc Foundation for .NET 6 and .NET Framework
https://docs.pdfsharp.net/
Other
531 stars 132 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 3 months ago

robrechtD commented 3 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 3 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 3 months ago

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