Fix ArrayIndexOutOfBoundsException in AES-GCM/CCM, correct CCM arg sanitization#151
Merged
rlm2002 merged 2 commits intowolfSSL:masterfrom Sep 3, 2025
Merged
Fix ArrayIndexOutOfBoundsException in AES-GCM/CCM, correct CCM arg sanitization#151rlm2002 merged 2 commits intowolfSSL:masterfrom
rlm2002 merged 2 commits intowolfSSL:masterfrom
Conversation
There was a problem hiding this comment.
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.
…put, correct CCM arg sanitization
…ck size boundaries
rlm2002
approved these changes
Sep 3, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The SunJCE test
crypto/provider/Cipher/AEAD/ReadWriteSkip.javawas 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.