Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Aug 25, 2025

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:

# gp -l
Invalid argument: AID must be between 5 and 16 bytes: 0

This was caused by BER-TLV tag C4 being present but with zero length, as shown in the issue trace:

[TRACE] GPRegistry - [c4] (empty - zero length)

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:

byte[] loadfileBytes = loadfiletag.getBytesValue();
if (loadfileBytes.length > 0) {
    e.setLoadFile(new AID(loadfileBytes));
} else {
    logger.warn("Skipping invalid load file AID (length: {})", loadfileBytes.length);
}

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.

@Copilot Copilot AI changed the title [WIP] Dear Copilot, please fix the issue in @martinpaljak/GlobalPlatformPro/issues/392 :) Fix zero-length AID handling in registry parsing (issue #392) Aug 25, 2025
@Copilot Copilot AI requested a review from martinpaljak August 25, 2025 04:00
Copilot finished work on behalf of martinpaljak August 25, 2025 04:00
@martinpaljak
Copy link
Owner

Thank, but no thanks

@martinpaljak
Copy link
Owner

@copilot root cause is correct. Fix only the single trouble-making location and use no more than 7 lines of code (except tests)

Copy link
Author

Copilot AI commented Aug 25, 2025

@copilot root cause is correct. Fix only the single trouble-making location and use no more than 7 lines of code (except tests)

Implemented minimal fix as requested. Changed only the C4 tag handling (6 lines) to check byte array length before AID creation. Tool now warns instead of crashing on zero-length load file AIDs. Commit 16337d0

@Copilot Copilot AI changed the title Fix zero-length AID handling in registry parsing (issue #392) Fix zero-length AID handling in C4 tag parsing (issue #392) Aug 25, 2025
Copilot finished work on behalf of martinpaljak August 25, 2025 08:59
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