empira / PDFsharp-1.5

A .NET library for processing PDF
MIT License
1.28k stars 588 forks source link

Avoid "Non-negative number required" Exception #110

Closed iquirino closed 1 year ago

iquirino commented 4 years ago

_lexer.Position = -1 cause System.IO.MemoryStream.set_Position to be -1. https://imgur.com/a/hy8TKdu

mitchcapper commented 4 years ago

It should be noted that PR only handles one condition in which this exception can occur, does not fix all non-negative number errors

iquirino commented 4 years ago

I work with thousands pdf in a day. This one is the only non negative exception tha i have catched.

I think it can be merged... And then you can solve other point... ?

iquirino commented 4 years ago

Is clear to me that idx validation need to be inside of startxref var instantiation

mitchcapper commented 4 years ago

Sorry @iquirino didn't mean to be rude, I actually am tracking down a dictionary read error on opening a PDF from an online system. It also generates this error and between this pr AND #95 I was hoping one of them addressed i (as pdfs open fine in acrobat). Sadly not.

My warning was just to others that this may not resolve all the stream seek isues.

    PdfSharp-wpf.dll!PdfSharp.Pdf.IO.Lexer.Position.set(int value) Line 71  C#
    PdfSharp-wpf.dll!PdfSharp.Pdf.IO.Parser.MoveToObject(PdfSharp.Pdf.PdfObjectID objectID) Line 80 C#
>   PdfSharp-wpf.dll!PdfSharp.Pdf.IO.Parser.ReadObject(PdfSharp.Pdf.PdfObject pdfObject, PdfSharp.Pdf.PdfObjectID objectID, bool includeReferences, bool fromObjecStream) Line 121  C#
    PdfSharp-wpf.dll!PdfSharp.Pdf.IO.Parser.GetStreamLength(PdfSharp.Pdf.PdfDictionary dict) Line 317   C#
    PdfSharp-wpf.dll!PdfSharp.Pdf.IO.Parser.ReadStream(PdfSharp.Pdf.PdfDictionary dict) Line 287    C#
    PdfSharp-wpf.dll!PdfSharp.Pdf.IO.Parser.ReadObject(PdfSharp.Pdf.PdfObject pdfObject, PdfSharp.Pdf.PdfObjectID objectID, bool includeReferences, bool fromObjecStream) Line 269  C#
    PdfSharp-wpf.dll!PdfSharp.Pdf.IO.PdfReader.Open(System.IO.Stream stream, string password, PdfSharp.Pdf.IO.PdfDocumentOpenMode openmode, PdfSharp.Pdf.IO.PdfPasswordProvider passwordProvider) Line 433  C#
    PdfSharp-wpf.dll!PdfSharp.Pdf.IO.PdfReader.Open(string path, string password, PdfSharp.Pdf.IO.PdfDocumentOpenMode openmode, PdfSharp.Pdf.IO.PdfPasswordProvider provider) Line 216  C#
    PdfSharp-wpf.dll!PdfSharp.Pdf.IO.PdfReader.Open(string path, PdfSharp.Pdf.IO.PdfDocumentOpenMode openmode) Line 186 C#
    testParse.dll!testParse.MainWindow.MainWindow_Loaded(object sender, System.Windows.RoutedEventArgs e) Line 51   C#
iquirino commented 4 years ago

PR #95 will solve this issue too or you need to replicate this in PR #95?

mitchcapper commented 4 years ago

95 actually did not, it seems its an issue when reading the dictionary during opening so while #95 solves some it didn't solve this. I am digging into it more but the .net core port seems more maintained so will probably submit more PR over there.

ThomasHoevel commented 1 year ago

Fixed in current internal builds of PDFsharp.

iquirino commented 1 year ago

Thank you! ;)