mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-19 10:47:56 +08:00
handle case where xref has multiple parts with incorrect offset #352
This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
parts.Add(part);
|
parts.Add(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CrossReferenceTable Build(long firstCrossReferenceOffset, ILog log)
|
public CrossReferenceTable Build(long firstCrossReferenceOffset, long offsetCorrection, ILog log)
|
||||||
{
|
{
|
||||||
CrossReferenceType type = CrossReferenceType.Table;
|
CrossReferenceType type = CrossReferenceType.Table;
|
||||||
DictionaryToken trailerDictionary = new DictionaryToken(new Dictionary<NameToken, IToken>());
|
DictionaryToken trailerDictionary = new DictionaryToken(new Dictionary<NameToken, IToken>());
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentPart = parts.FirstOrDefault(x => x.Offset == prevBytePos);
|
currentPart = parts.FirstOrDefault(x => x.Offset == prevBytePos || x.Offset == prevBytePos + offsetCorrection);
|
||||||
if (currentPart == null)
|
if (currentPart == null)
|
||||||
{
|
{
|
||||||
log.Warn("Did not found XRef object pointed to by 'Prev' key at position " + prevBytePos);
|
log.Warn("Did not found XRef object pointed to by 'Prev' key at position " + prevBytePos);
|
||||||
@@ -88,7 +88,7 @@
|
|||||||
// merge used and sorted XRef/trailer
|
// merge used and sorted XRef/trailer
|
||||||
foreach (long bPos in xrefSeqBytePos)
|
foreach (long bPos in xrefSeqBytePos)
|
||||||
{
|
{
|
||||||
var currentObject = parts.First(x => x.Offset == bPos);
|
var currentObject = parts.First(x => x.Offset == bPos || x.Offset == bPos + offsetCorrection);
|
||||||
if (currentObject.Dictionary != null)
|
if (currentObject.Dictionary != null)
|
||||||
{
|
{
|
||||||
foreach (var entry in currentObject.Dictionary.Data)
|
foreach (var entry in currentObject.Dictionary.Data)
|
||||||
|
@@ -207,7 +207,7 @@
|
|||||||
throw new PdfDocumentFormatException("The cross reference was not found.");
|
throw new PdfDocumentFormatException("The cross reference was not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var resolved = table.Build(crossReferenceLocation, log);
|
var resolved = table.Build(crossReferenceLocation, offsetCorrection, log);
|
||||||
|
|
||||||
// check the offsets of all referenced objects
|
// check the offsets of all referenced objects
|
||||||
if (!CrossReferenceObjectOffsetValidator.ValidateCrossReferenceOffsets(bytes, resolved, log, out var actualOffsets))
|
if (!CrossReferenceObjectOffsetValidator.ValidateCrossReferenceOffsets(bytes, resolved, log, out var actualOffsets))
|
||||||
|
Reference in New Issue
Block a user