Skip to content

Fix handling of signature fields with multiple instances#212

Merged
VahidN merged 1 commit intoVahidN:masterfrom
WitkacDevelopers:fix/sigfields_with_multiple_instances
Sep 27, 2025
Merged

Fix handling of signature fields with multiple instances#212
VahidN merged 1 commit intoVahidN:masterfrom
WitkacDevelopers:fix/sigfields_with_multiple_instances

Conversation

@WitkacDevelopers
Copy link
Copy Markdown

@WitkacDevelopers WitkacDevelopers commented Sep 26, 2025

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows Conventional Commits
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Other... Please describe:

What is the current behavior?

In some cases Signatures have more than one instance with the same name, ie multiple rects in pdf, then Merged has more than one item. Not always first item of Merged references to signature dictionary.

Example case of multiple representation of Signature1 field in PDF Document:

55 0 obj
<< /Rect [ 421 359 539 410 ] /Border [ 0 0 0 ] /T (Signature1) /F 132 /Subtype
/Widget /DA (/Helvetica 12 Tf 0 g) /AP 107 0 R /AAPL:AKExtras 108 0 R /FT
/Sig /Type /Annot /Ff 0 >>
endobj
109 0 obj
<< /Type /Annot /T (Signature1) /AP 107 0 R /Rect [ 421 359 539 410 ] /Border
[ 0 0 0 ] /Ff 0 /DA (/Helvetica 12 Tf 0 g) /F 132 /FT /Sig /Subtype /Widget
>>
endobj

Closes #

What is the new behavior?

This PR finds for Merged item which contains reference to signature dictionary (V field)

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @WitkacDevelopers, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a bug in the handling of PDF signature fields, particularly when a signature has multiple representations or instances within the document. Previously, the system might incorrectly identify the signature dictionary, leading to issues in verification or retrieval. The updated logic now intelligently searches for the correct signature dictionary among multiple merged items, ensuring accurate processing of digital signatures in complex PDF structures.

Highlights

  • Improved Signature Field Handling: The pull request addresses an issue where PDF signature fields with multiple instances (e.g., multiple 'Rect' entries) were not correctly processed, especially when the first 'Merged' item did not reference the signature dictionary.
  • Accurate Signature Dictionary Retrieval: The logic for retrieving the signature dictionary (keyed by '/V') from 'AcroFields' has been enhanced to correctly identify the relevant 'Merged' item by searching for the one that contains the '/V' key, rather than assuming it's always the first one.
  • Robust Signature Name Detection: The 'findSignatureNames' method now also correctly identifies signature fields by searching for the appropriate 'Merged' dictionary containing the '/V' key, improving the reliability of signature detection.
  • New Functional Tests: Dedicated functional tests ('PdfVerifySignatureTests.cs') have been added to ensure the correct detection and verification of signature fields, specifically for the scenario involving multiple instances, confirming the bug fix.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@what-the-diff
Copy link
Copy Markdown

what-the-diff Bot commented Sep 26, 2025

PR Summary

  • Introduction of New Functional Test Class:
    A new test class called PdfVerifySignatureTests has been added. This class has methods that allow us to verify any signatures present in PDF files. It works by reading a PDF file and examining its signature fields.

  • Addition of a new PDF file for testing:
    A new PDF file named issue_sig_fields.pdf has been brought in to help with testing the new functionalities.

  • Improvements to existing code:
    The AcroFields.cs file, which is instrumental in handling signature fields in PDF files, has been updated. Enhancements were made to methods responsible for signature detection. In addition to this, null checks were added to prevent possible errors when a signature isn't found. The code was also refactored for increasing understanding and efficiency by specifically looking for the first dictionary containing a specific key.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request successfully addresses a bug concerning the handling of signature fields with multiple instances by correctly identifying the signature dictionary. The logic is sound, and the inclusion of new functional tests is a great addition to ensure the fix is robust. I have a few suggestions to further improve the code, mainly focusing on the new test file for better readability and maintainability.

Comment thread src/iTextSharp.LGPLv2.Core/iTextSharp/text/pdf/AcroFields.cs
Comment thread src/iTextSharp.LGPLv2.Core/iTextSharp/text/pdf/AcroFields.cs
@VahidN VahidN merged commit c342473 into VahidN:master Sep 27, 2025
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.

3 participants