Skip to content

Commit e9204d8

Browse files
committed
optional owner password check
1 parent 9c9fa54 commit e9204d8

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/foundation/src/PDFsharp/src/PdfSharp/Pdf.IO/PdfReader.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ PdfDocument OpenFromStream(Stream stream, string? password, PdfDocumentOpenMode
288288
_document.Options.EnableOwnBinaryHeader = _options.EnableOwnBinaryHeader;
289289
_document.Options.EnableLineBreakInArrayObjects = _options.EnableLineBreakInArrayObjects;
290290
_document.Options.DisablePagesAndCatalogAtEnd = _options.DisablePagesAndCatalogAtEnd;
291+
_document.Options.EnableSecurityChecks = _options.EnableSecurityChecks;
291292

292293
_document._state |= DocumentState.Imported;
293294
_document._openMode = openMode;
@@ -380,7 +381,11 @@ PdfDocument OpenFromStream(Stream stream, string? password, PdfDocumentOpenMode
380381
goto TryAgain;
381382
}
382383
else
383-
throw new PdfReaderException(PsMsgs.OwnerPasswordRequired);
384+
{
385+
if(_document.Options.EnableSecurityChecks)
386+
throw new PdfReaderException(PsMsgs.OwnerPasswordRequired);
387+
_document.SecuritySettings.HasOwnerPermissions = true;
388+
}
384389
}
385390
// ReSharper restore RedundantIfElseBlock
386391
}

src/foundation/src/PDFsharp/src/PdfSharp/Pdf.IO/PdfReaderOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ public class PdfReaderOptions
141141

142142
public bool DisablePagesAndCatalogAtEnd { get; set; } = true;
143143

144+
public bool EnableSecurityChecks { get; set; } = true;
145+
144146
// Testing only
145147

146148
//public bool UseOldCode { get; set; } = false;

src/foundation/src/PDFsharp/src/PdfSharp/Pdf/PdfDocumentOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ public PdfUseFlateDecoderForJpegImages UseFlateDecoderForJpegImages
126126

127127
public bool DisablePagesAndCatalogAtEnd { get; set; } = true;
128128

129+
public bool EnableSecurityChecks { get; set; } = true;
130+
129131
public string LineEnding => EnableLfLineEndings ? "\n" : "\r\n";
130132

131133
public byte[] LineEndingBytes => Encoding.ASCII.GetBytes(LineEnding);

0 commit comments

Comments
 (0)