PdfSharpCore icon indicating copy to clipboard operation
PdfSharpCore copied to clipboard

Number with 10 digits after decimal causes CLexer ScanNumber() to throw IndexOutOfBoundsException

Open search4sound opened this issue 5 years ago • 1 comments

My file has the number -3.1428571429. In CLexer ScanNumber(), period equals true and decimalDigits equals 10. The PowersOf10 array contains 10 items (zero based index so max is 9), so since decimalDigits = 10, it throws an IndexOutOfBoundsException when it attempts to do this:

_tokenAsReal = value / PowersOf10[decimalDigits];

Note I'm on v1.2.6, using in a .NET Core 3.1 app running on Windows.

Are 10-digit decimals in a PDF file unusual? This number is in the internal structure, not visible in the PDF. Is this something that can be avoided in the PDF by using a different resolution setting? Or have I found an issue that needs to be addressed in the code (in which case I could submit a PR - one solution would be to convert all cases of the double data type to a decimal and add more items to the PowersOf10 array - total of 20 should be sufficient).

search4sound avatar Oct 13 '20 21:10 search4sound

PdfSharp has one power of 10 more: https://github.com/empira/PDFsharp/blob/3205bd933b464d150c0f42e8bcdff3314b6c6164/src/PdfSharp/Pdf.Content/CLexer.cs#L365 vs: https://github.com/ststeiger/PdfSharpCore/blob/938ac6bf52dcb1e308a4c1b1cacf315a7ddb632b/PdfSharpCore/Pdf.Content/CLexer.cs#L313 Is that enough?

mishun avatar Mar 11 '21 22:03 mishun