We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Fail to enumerate pages in certain Pdf documents

Hello Aspose team,

I encountered System.NullReferenceException in Aspose.PDF.dll when enumerating pages in some Pdf documents. On Windows the page variable assgined null value while on Linux the program crashes.

Environment: Linux and Windows, .NET Core 5.0

Sample code:
var inputFile = “/path/to/sample”;
using (Stream fileStream = new FileStream(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
Document pdfDocument = new Document(fileStream);
PageCollection pages = pdfDocument.Pages;
Console.WriteLine($“Page count: {pages.Count}”);
foreach (var page in pages)
{
// Do something
}
}

Sample documents:
samples.zip (8.1 KB)

@dunghnguyen

We have tested the scenario using the latest version of Aspose.PDF for .NET 22.1 and have not found the shared issue. So, please use Aspose.PDF for .NET 22.1.

Thank for your prompt reply.
I used the latest Aspose.PDF for testing. Running the test program under debugger, I can see that Segmentation fault raised.

image.png (13.4 KB)

I suspect this is the reason why it crashes my application. Below is the stacktrace when my application fails, I can’t debug further.

image.png (7.0 KB)

Could you please try with my samples again?

@dunghnguyen

Your PDF file contains virus and it is blocked by Windows defender. Moreover, if we open the PDF in Adobe reader, it also shows error message. We disabled the Windows defender to test this case. Please make sure that you are using the valid PDF file.

@tahir.manzoor
Thank you for your effort in supporting us.
I understand that the sample is invalid and it is fine to get a failure when parsing it.
However, I expect that the behavior on Windows and Linux should be the same, i.e., returning null page.
I am using Aspose.PDF for several features including validation of PDF files. In case of invalid files, I wish that Aspose.PDF can return null page for further check and appropriate results.
Can you please check further if we can make the results the same between Windows and Linux?

Thanks

@dunghnguyen

We tested the scenario using the latest version of Aspose.PDF for .NET 22.1 and PageCollection.Pages property does not return null value. So, please use Aspose.PDF for .NET 22.1.