From d1f59f345642b35bba2ba2b94267d62cdde2aa33 Mon Sep 17 00:00:00 2001 From: Mitch Capper Date: Thu, 5 Sep 2019 01:14:27 -0700 Subject: [PATCH] Allow uints(PdfUInteger) when calling ReadInt to support some encrypted file header reading. This allows reading of uints by ReadInt and converts them to negative integers. This allows for reading some headers with other encryption options, even if we don't support that encryption type (useful if pdf still has read access without). Should not break most existing code unless code expected an exception for reading uints and was catching it. --- src/PdfSharp/Pdf/PdfDictionary.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/PdfSharp/Pdf/PdfDictionary.cs b/src/PdfSharp/Pdf/PdfDictionary.cs index 428140a1..aed19775 100644 --- a/src/PdfSharp/Pdf/PdfDictionary.cs +++ b/src/PdfSharp/Pdf/PdfDictionary.cs @@ -407,7 +407,10 @@ public int GetInteger(string key, bool create) if (integerObject != null) return integerObject.Value; - throw new InvalidCastException("GetInteger: Object is not an integer."); + PdfUInteger uinteger = obj as PdfUInteger; + if (uinteger != null) + return (int)uinteger.Value; + throw new InvalidCastException("GetInteger: Object is not an integer."); } ///