skip offsets outside of file bounds

This commit is contained in:
EliotJones 2025-08-03 13:34:02 -05:00
parent 037b79cd5d
commit 4409998de9
4 changed files with 36 additions and 30 deletions

View File

@ -1,32 +1,36 @@
namespace UglyToad.PdfPig.Tests.Integration
{
using System.Diagnostics;
//using System.Diagnostics;
/// <summary>
/// A class for testing files which are not checked in to source control.
/// </summary>
public class LocalTests
{
[Fact]
public void Tests()
{
var file = @"D:\temp\digitalcorpora\0001\0001849.pdf";
try
{
using (var document = PdfDocument.Open(file, new ParsingOptions { UseLenientParsing = false }))
{
for (var i = 1; i <= document.NumberOfPages; i++)
{
var page = document.GetPage(i);
var text = page.Text;
Trace.WriteLine(text);
}
}
}
catch (Exception ex)
{
throw new InvalidOperationException($"Error parsing: {Path.GetFileName(file)}.", ex);
}
}
//[Fact]
//public void Tests()
//{
// var files = Directory.GetFiles(@"C:\temp\pdfs", "*.pdf");
// foreach (var file in files)
// {
// try
// {
// using (var document = PdfDocument.Open(file, new ParsingOptions { UseLenientParsing = false }))
// {
// for (var i = 1; i <= document.NumberOfPages; i++)
// {
// var page = document.GetPage(i);
// var text = page.Text;
// Trace.WriteLine(text);
// }
// }
// }
// catch (Exception ex)
// {
// throw new InvalidOperationException($"Error parsing: {Path.GetFileName(file)}.", ex);
// }
// }
//}
}
}

View File

@ -17,6 +17,11 @@ internal static class XrefStreamParser
ISeekableTokenScanner scanner,
ILog log)
{
if (xrefOffset >= bytes.Length || xrefOffset < 0)
{
return null;
}
var offsetCorrectionType = XrefOffsetCorrection.None;
var offsetCorrection = 0L;

View File

@ -16,6 +16,11 @@ internal static class XrefTableParser
ISeekableTokenScanner scanner,
ILog log)
{
if (xrefOffset >= bytes.Length || xrefOffset < 0)
{
return null;
}
bytes.Seek(xrefOffset);
var correctionType = XrefOffsetCorrection.None;

View File

@ -1,8 +0,0 @@
{
"profiles": {
"UglyToad.PdfPig.ConsoleRunner": {
"commandName": "Project",
"commandLineArgs": "\"C:\\temp\\pdfs\\archive\""
}
}
}