Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Tests/PdfNormalizerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ public void LeavesLookalikeKeysUntouched()
Assert.That(Normalize(input), Is.EqualTo(input));
}

[Test]
public void HandlesUnterminatedFileIdWithoutOverrunning()
{
// A truncated /ID whose string runs to the end of the buffer with no closing '>'/')' (and no
// closing ']') must not scan past the buffer: the value is zeroed as far as it exists and the
// scan stops cleanly rather than throwing. Hex string form (no closing '>'):
Assert.That(Normalize("/ID [<ABCD"), Is.EqualTo("/ID [<0000"));
// Literal string form (no closing ')'):
Assert.That(Normalize("/ID [(ABCD"), Is.EqualTo("/ID [(0000"));
}

[Test]
public void NormalizedDocumentStillLoads()
{
Expand Down
10 changes: 8 additions & 2 deletions src/Verify.DocNet/PdfNormalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,20 @@ static void ZeroFileId(byte[] data)
var start = i + 1;
i = FindByte(data, start, (byte) '>');
Overwrite(data, start, i, Fill.Hex);
i++;
if (i < data.Length)
{
i++;
}
}
else if (data[i] == (byte) '(')
{
var start = i + 1;
i = FindLiteralEnd(data, start);
Overwrite(data, start, i, Fill.All);
i++;
if (i < data.Length)
{
i++;
}
}
else
{
Expand Down
Loading