Skip to content

Comments

Fix ArrayIndexOutOfBoundsException in AES-GCM/CCM, correct CCM arg sanitization#151

Merged
rlm2002 merged 2 commits intowolfSSL:masterfrom
cconlon:aesCcmFix
Sep 3, 2025
Merged

Fix ArrayIndexOutOfBoundsException in AES-GCM/CCM, correct CCM arg sanitization#151
rlm2002 merged 2 commits intowolfSSL:masterfrom
cconlon:aesCcmFix

Conversation

@cconlon
Copy link
Member

@cconlon cconlon commented Sep 3, 2025

The SunJCE test crypto/provider/Cipher/AEAD/ReadWriteSkip.java was failing when run with wolfJCE as the provider, throwing: ArrayIndexOutOfBoundsException: arraycopy: source index -16 out of bounds for byte[0]. This also fixes SunJCE test: crypto/provider/Cipher/AEAD/GCMBufferTest.java.

This occurred when processing zero-length plaintext in AES-GCM/CCM modes where the input consists only of the authentication tag (16 bytes).

This PR adds bounds checking before tag extraction in both AES-GCM and AES-CCM decrypt paths, validates that input length is at least equal to tag length, and throws appropriate AEADBadTagException if input is too short.

JUnit test is included for regression prevention.

@cconlon cconlon self-assigned this Sep 3, 2025
@cconlon cconlon requested a review from Copilot September 3, 2025 16:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an ArrayIndexOutOfBoundsException in AES-GCM/CCM modes when processing zero-length plaintext with authentication tags. The fix adds proper bounds checking before tag extraction and validates input length requirements.

  • Added bounds checking in WolfCryptCipher.java to prevent ArrayIndexOutOfBoundsException when input is shorter than tag length
  • Updated CCM argument validation in JNI layer to properly handle null input when length is zero
  • Modified existing tests to reflect that null input with valid AAD should succeed rather than fail

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java Added input length validation before tag extraction in GCM/CCM decrypt paths
jni/jni_aesccm.c Updated argument validation to allow null input when length is zero and added proper parameter bounds checking
src/test/java/com/wolfssl/wolfcrypt/test/AesCcmTest.java Updated test expectations to reflect that null input with AAD should succeed
src/test/java/com/wolfssl/provider/jce/test/WolfCryptCipherTest.java Added comprehensive regression test for zero-length plaintext in AES-GCM/CCM modes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@rlm2002 rlm2002 merged commit 3bf3309 into wolfSSL:master Sep 3, 2025
46 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