mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-03-10 00:23:29 +08:00
#405 check encryption token value for null
This commit is contained in:
@@ -417,6 +417,35 @@ endobj";
|
|||||||
Assert.Equal(3, third.Number.ObjectNumber);
|
Assert.Equal(3, third.Number.ObjectNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ReadsDictionaryContainingNull()
|
||||||
|
{
|
||||||
|
const string input = @"14224 0 obj
|
||||||
|
<</Type /XRef
|
||||||
|
/Root 8 0 R
|
||||||
|
/Prev 116
|
||||||
|
/Length 84
|
||||||
|
/Size 35
|
||||||
|
/W [1 3 2]
|
||||||
|
/Index [0 1 6 1 8 2 25 10]
|
||||||
|
/ID [ (ù¸7<C2B8>ãA×<41>žòÜ4<C39C><34>Š•)]
|
||||||
|
/Info 6 0 R
|
||||||
|
/Encrypt null>>
|
||||||
|
endobj";
|
||||||
|
|
||||||
|
var scanner = GetScanner(input);
|
||||||
|
|
||||||
|
var tokens = ReadToEnd(scanner);
|
||||||
|
|
||||||
|
var dictionaryToken = tokens[0].Data as DictionaryToken;
|
||||||
|
|
||||||
|
Assert.NotNull(dictionaryToken);
|
||||||
|
|
||||||
|
var encryptValue = dictionaryToken.Data["Encrypt"];
|
||||||
|
|
||||||
|
Assert.IsType<NullToken>(encryptValue);
|
||||||
|
}
|
||||||
|
|
||||||
private static PdfTokenScanner GetScanner(string s, TestObjectLocationProvider locationProvider = null)
|
private static PdfTokenScanner GetScanner(string s, TestObjectLocationProvider locationProvider = null)
|
||||||
{
|
{
|
||||||
var input = StringBytesTestConverter.Convert(s, false);
|
var input = StringBytesTestConverter.Convert(s, false);
|
||||||
|
|||||||
@@ -162,17 +162,7 @@
|
|||||||
private static (IndirectReference, DictionaryToken) ParseTrailer(CrossReferenceTable crossReferenceTable, bool isLenientParsing, IPdfTokenScanner pdfTokenScanner,
|
private static (IndirectReference, DictionaryToken) ParseTrailer(CrossReferenceTable crossReferenceTable, bool isLenientParsing, IPdfTokenScanner pdfTokenScanner,
|
||||||
out EncryptionDictionary encryptionDictionary)
|
out EncryptionDictionary encryptionDictionary)
|
||||||
{
|
{
|
||||||
encryptionDictionary = null;
|
encryptionDictionary = GetEncryptionDictionary(crossReferenceTable, pdfTokenScanner);
|
||||||
|
|
||||||
if (crossReferenceTable.Trailer.EncryptionToken != null)
|
|
||||||
{
|
|
||||||
if (!DirectObjectFinder.TryGet(crossReferenceTable.Trailer.EncryptionToken, pdfTokenScanner, out DictionaryToken encryptionDictionaryToken))
|
|
||||||
{
|
|
||||||
throw new PdfDocumentFormatException($"Unrecognized encryption token in trailer: {crossReferenceTable.Trailer.EncryptionToken}.");
|
|
||||||
}
|
|
||||||
|
|
||||||
encryptionDictionary = EncryptionDictionaryFactory.Read(encryptionDictionaryToken, pdfTokenScanner);
|
|
||||||
}
|
|
||||||
|
|
||||||
var rootDictionary = DirectObjectFinder.Get<DictionaryToken>(crossReferenceTable.Trailer.Root, pdfTokenScanner);
|
var rootDictionary = DirectObjectFinder.Get<DictionaryToken>(crossReferenceTable.Trailer.Root, pdfTokenScanner);
|
||||||
|
|
||||||
@@ -183,5 +173,28 @@
|
|||||||
|
|
||||||
return (crossReferenceTable.Trailer.Root, rootDictionary);
|
return (crossReferenceTable.Trailer.Root, rootDictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static EncryptionDictionary GetEncryptionDictionary(CrossReferenceTable crossReferenceTable, IPdfTokenScanner pdfTokenScanner)
|
||||||
|
{
|
||||||
|
if (crossReferenceTable.Trailer.EncryptionToken == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!DirectObjectFinder.TryGet(crossReferenceTable.Trailer.EncryptionToken, pdfTokenScanner, out DictionaryToken encryptionDictionaryToken))
|
||||||
|
{
|
||||||
|
if (DirectObjectFinder.TryGet(crossReferenceTable.Trailer.EncryptionToken, pdfTokenScanner, out NullToken _))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new PdfDocumentFormatException($"Unrecognized encryption token in trailer: {crossReferenceTable.Trailer.EncryptionToken}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = EncryptionDictionaryFactory.Read(encryptionDictionaryToken, pdfTokenScanner);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user