Java4Shell: what changed in the Base64 decoder
The fix for Java4Shell is small: check that at least four input bytes remain before entering the AVX-512 Base64 decoder’s final-fragment path. The two commits I reviewed describe this as “Base64 optimization improvements.” Neither commit message mentions a vulnerability, a CVE, heap corruption or remote code execution. Corretto commit, OpenJDK commit.
That description is rather understated for a missing check that allows a decoder to write outside its output buffer.
But the wider GitHub record is more explicit. An earlier OpenJDK pull request described the heap corruption and proposed the same guard. Corretto’s release changelog also names CVE-2026-114938. The security information exists; it just isn’t in the commit message. Original PR, Corretto changelog.
Calif’s Java4Shell write-up describes how the Base64 memory corruption can lead to remote code execution through applications using the affected JVM. The path requires x86-64 hardware with AVX-512 VBMI support and execution of the vulnerable intrinsic. ARM64 is unaffected. Exploitation also depends on the application: Calif describes separate attack chains, rather than a payload that works against every Java service.
I wanted to follow the fix itself: where it lives, what the new condition prevents, and how clearly the public changes explain its purpose.
The change is in HotSpot
The starting point was a README recording a comparison of two Amazon Corretto 27 Linux x64 distributions:
| Distribution | Role in the comparison |
|---|---|
amazon-corretto-27.0.1.0.11-linux-x64 | Older build |
amazon-corretto-27.0.1.1.4-linux-x64 | Newer build containing the fix |
The notes report that the Java java.util.Base64 source is unchanged between
these builds. The relevant binary is lib/server/libjvm.so, and the source
change is in:
src/hotspot/cpu/x86/stubGenerator_x86_64.cpp
StubGenerator::generate_base64_decodeBlock()
This is the native code generator for the decoder stub. HotSpot can use that stub when compiling a call to the Base64 decoder. Reading only the Java implementation therefore misses the change that matters here.
The Corretto patch adds the following immediately after
L_finalBit, where the AVX-512 path handles the remaining input:
// A padded Base64 tail shorter than one complete block is handled by Java.
__ cmpl(length, 4);
__ jcc(Assembler::less, L_bruteForce);
The OpenJDK patch contains the same addition in the same function. Both diffs change only this source file.
Why four bytes matter
The final-fragment code derives its output size from complete groups of four Base64 input bytes. It then subtracts the padding bytes. With fewer than four bytes remaining, the first calculation produces zero. Subtracting padding turns that into a negative value. The original PR explains this failure, and the surrounding source shows the operations:
output_size = (remaining_input / 4) * 3
output_size -= padding
That value is then used to construct the mask for a vector store. A negative size produces an all-ones mask on this path, enabling all 64 byte lanes. The decoder consequently performs a full vector write where only a small tail should have been possible. Java can still reject the malformed input afterwards, but that exception arrives after the native write.
The new condition prevents the short tail from reaching this calculation.
Despite its name, L_bruteForce does not decode an incomplete group here. The
fallback eventually counts complete four-byte groups; a tail shorter than
four leaves none to process and returns control so Java can handle it. This
also means the guard covers all tails shorter than four bytes, even though the
comment calls out padded tails. Decoder and fallback source.
The fix restores a necessary precondition for the vector code. Catching
IllegalArgumentException in application code cannot substitute for it.
What the binary comparison shows
The README records the compiled code generator growing from 0x2650 to
0x267d bytes, a difference of 45 bytes. Its newer disassembly contains this
additional sequence, with intervening instructions omitted:
mov $0x4, %edx
mov $0xe, %esi
call Assembler::cmpl(Register, int)
...
mov $0xc, %esi
call Assembler::jcc(Assembler::Condition, Label&, bool)
There are two levels of code involved. These are instructions in the C++ generator calling assembler helpers. Those helpers emit the comparison and conditional branch into the decoder stub. The 45-byte increase is therefore in the generator, not a measurement of the emitted guard.
The recorded sequence is consistent with the source patch. The binary sizes and unchanged Java source are observations from the supplied comparison notes; I checked the GitHub source changes for this post but did not repeat the binary comparison or run an exploit against these distributions.
Did the changes mention the vulnerability?
It depends on which part of GitHub you read.
| Public record | What it says |
|---|---|
Corretto 564fc7de | 8393212: Base64 optimization improvements, followed by a backport reference. No CVE or security impact in the message. |
OpenJDK 5177a70b | The same title, with co-author and reviewer credits. No CVE or security impact in the message. |
| OpenJDK PR #32781 | Describes an output-buffer overwrite on a short padded tail, explains the bad mask and heap corruption, and proposes the same guard. Closed without merging. |
| Corretto 27.0.1.1.4 changelog | Explicitly lists CVE-2026-114938 as addressed, under hotspot/compiler, with a CVSS score of 8.1. |
Albert Yang opened the original PR on 9 September. It included both the guard
and a regression test, TestBase64AVX512.java. The test forces compilation of
the decoder, checks valid input, and then checks that malformed input is
rejected without overwriting canary bytes beyond the logical output length.
That last check matters: a test which only expects an exception could miss
the corruption entirely. PR description and diff.
The later discussion also names the security impact. On 19 November, a comment linked Java4Shell and referred to RCE. On 20 November, Yang explained that others had taken over the fix and that the issue was resolved on master. The closed PR should therefore not be read as evidence that the fix was abandoned.
There is a separate testing question. Neither of the two shipped commit diffs includes the regression test from the original PR. A 23 November comment asks about bringing it into OpenJDK; Yang’s reply suggests broader input and CPU-extension coverage. This establishes what these patches contain, not that the project has no other relevant tests.
The release documentation is clearer than the commits. Beyond Corretto’s GitHub changelog, Oracle’s November advisory names the CVE and credits Albert Yang and Quang Luong. AWS’s bulletin describes the Base64 out-of-bounds write and identifies fixed Corretto builds. Calling this an undisclosed security fix would be inaccurate. Calling the commit title unhelpful to someone assessing update urgency seems fair.
Updating the code that actually runs
For the Corretto 27 comparison here, the fixed release is 27.0.1.1.4. The release changelog dates it to 17 November 2026 and explicitly includes this CVE. Other Java versions and distributions have their own fixed builds; the full runtime version matters.
Update the runtime and restart the Java application so it loads the patched
VM. If an immediate update is impractical, AWS documents
-XX:-UseBASE64Intrinsics as an interim mitigation. That option must be applied
to the JVM running the service. AWS update guidance.
For me, the useful lesson in this patch is how much can sit behind a familiar Java API. The application calls a decoder, the VM selects a native implementation, and a missing precondition in that implementation breaks the memory-safety guarantee the caller expects. The source fix is only a comparison and a branch. Its purpose deserves a clearer description than an optimization improvement.
#Java #OpenJDK #Corretto #CVE-2026-114938 #Memory Safety #Reverse Engineering