Fix zero-length AID handling in C4 tag parsing (issue #392) #393
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes issue where GlobalPlatformPro would crash with
IllegalArgumentException: AID must be between 5 and 16 bytes: 0
when encountering cards with corrupted registry entries containing zero-length load file AIDs.Problem
Cards with corrupted registry data containing zero-length C4 (load file AID) tags would make the tool completely unusable:
This was caused by BER-TLV tag C4 being present but with zero length, as shown in the issue trace:
Solution
Added minimal validation in the C4 tag handling to check byte array length before AID creation. The fix consists of only 6 lines of code that validate the load file AID bytes and log a warning instead of crashing:
Result
The tool now continues working even with corrupted cards:
# gp -l [WARN] GPRegistry - Skipping invalid load file AID (length: 0) ISD: A000000003000000 (INITIALIZED) APP: [other valid entries shown normally]
This provides graceful degradation - the tool remains fully functional while warning users about corrupted data instead of crashing.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.