Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix negative index error on RemoveUnusedNode when open pdf with … #148

Merged
merged 1 commit into from
Jul 24, 2024

Conversation

juniorschroder
Copy link
Contributor

Hello @VahidN, how are you?
We are using your fork of iTextSharp in our software and have encountered a very specific issue. We have a PDF document that contains a link element with a reference that appears to be invalid:
pdf_file_content

This does not compromise the PDF itself, but it generates an error when opening the PDF with the PdfReader class:
error_at_open

I am opening this pull request with the correction made. Unfortunately, I couldn't find another PDF with the same problem, and the PDF I have is owned by a client, so I don't have permission to share it. For this reason, I am not including a test along with the code.

Copy link

what-the-diff bot commented Jul 24, 2024

PR Summary

  • Improved Condition Checking in 'RemoveUnusedNode'
    The conditions used within this method in PdfReader.cs were refined. The reasoning behind this change is to ensure accuracy when performing actions depending on these conditions. Previously it just checked if a particular node was accessed (!hits[num]), now the condition also checks if num is greater than 0 (num > 0 && !hits[num]). This adds another layer of verification before proceeding with further actions.

  • Enhanced 'num' Validations in 'RemoveUnusedNode' Method
    The modified conditions now incorporate additional validation related to num. The updated condition extends the existing check for the range and 'null' state of _xrefObj[num] to also ensure that num > 0. This adjustment not only prevents potential errors from handling invalid data but also correctly handles edge cases involving _xrefObj[num] where num equals 0.

@VahidN VahidN merged commit 5618985 into VahidN:master Jul 24, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants