empira / PDFsharp

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

Ensure all trailers security handlers are initialized at parsing time #161

Open Greybird opened 1 month ago

Greybird commented 1 month ago

Currently, the Encrypt key is only read for the document trailer. However, when mutliple trailers are present, the code for reading all indirect objects in ReadAllIndirectObjects can lead to calling IsSecurityHandler method, that can iterate over SecurityHandlers for all previous trailers. The lazy initialization code will access the Encrypt key under the asumption that it has been read already, leading to an exception.

Unfortunately, I cannot share the file leading to this discovery, sorry for this.