Java4Shell: OpenJDK Base64 Bug Turns 65 Bytes Into RCE
Java4Shell is a memory-corruption flaw in OpenJDK's AVX-512 Base64 decoder. How 65 bytes trigger heap corruption and RCE — and how to mitigate it now.

Sixty-four letter A's and a single equals sign. That's the entire input needed to corrupt the heap of an unpatched OpenJDK server — a 65-character Base64 string that walks straight past Java's famous memory safety and scribbles 62 bytes past the end of an array. The vulnerability, disclosed by security firm Calif as Java4Shell (CVE-2026-114938, CVSS 9.2), sits not in application code but in hand-rolled assembly buried inside the JVM's Base64 decoder. Pre-auth remote code execution was demonstrated against Keycloak, Jenkins, Jira, Confluence, Artifactory, and PingFederate. If your organization runs Java on x86-64 servers — and statistically, it does — this one is your problem.
I cover vulnerabilities for a living, and most of them blur together: another deserialization bug, another auth bypass, another path traversal. Java4Shell is different, and not because of the score. It's different because of where it lives. The bug is in an optimization — a speed-up for decoding Base64 using AVX-512 vector instructions — that almost no application on Earth actually needs. The story of how it was found, how it was exploited, and why your proxies might already be saving you says a lot about where software security is heading.
The Problem: A JIT Intrinsic With a Broken Mask
To understand the bug, you need to know how OpenJDK makes Base64 fast. The HotSpot JVM watches which methods run hot and lets its C2 compiler turn them into native code. For certain operations it goes further, swapping in hand-tuned assembly routines called intrinsics that use specialized CPU instructions. On x86-64 chips with AVX-512 VBMI support, Base64 decoding gets exactly this treatment: the intrinsic chews through input in 256- or 64-byte blocks, using the VMOVDQU8 instruction with a 64-bit mask that decides which bytes get written to the destination buffer.
The flaw is in how that mask gets computed for the padded tail of an input. Base64 pads its output with = characters, and the assembly adjusts the output length downward for each padding byte it sees. For certain malformed inputs — a lone = at the end of a block, for instance — the computed output length underflows to -1 or -2. That negative value flows into a bit-manipulation instruction (bzhiq) which, for inputs of 64 or above, leaves the mask unchanged: all 64 bits set. Every bit set means every byte written.
Walk through the concrete trigger. You send 64 A's followed by =, 65 characters total. The JVM calculates the decoded length as 50 bytes and allocates a 50-byte array. The intrinsic decodes the first 64 characters fine, then hits the stray equals sign, underflows the length, sets the full mask — and fires off a 64-byte vectorized write starting near the end of a 50-byte buffer. Sixty-two bytes of neighboring heap objects get stomped with attacker-influenced constant data. Java's own validation code does eventually notice the input is invalid and throws IllegalArgumentException, but by then the damage is done. The exception handler is mopping the floor while the house is already on fire.
// Pseudocode of the mask calculation (after Calif's write-up)
input_mask := bzhiq(-1, input_length)
output_len := (input_length / 4) * 3
// handle padding
if input[input_length - 1] == '=':
output_len -= 1
input_mask >>= 1
if input[input_length - 2] == '=':
output_len -= 1
input_mask >>= 1
// For a lone '=' tail, output_len was already 0
// -> now it's -1, and bzhiq(-1, 255) leaves all bits set
output_mask := bzhiq(-1, output_len) // == -1u64, all 64 bits 1
// evmovdqub then writes all 64 bytes where ~50 were allocated
One detail matters for your triage: this only executes on x86-64 hosts whose CPUs support AVX-512 VBMI. ARM servers like AWS Graviton never run the buggy stub, and neither do older Xeons. The vulnerable code path also only appears in HotSpot-based JVMs — OpenJDK, Oracle JDK, GraalVM. OpenJ9 and Azul Prime, which use different JIT architectures, are unaffected. On OpenJDK 17, incidentally, the trigger is 128 A's plus = rather than 64, because the threshold for entering the fast path is higher. Small differences, but they matter if you're writing detection rules.
Failed Attempt One: "Java Is Memory Safe"
The first reaction across engineering Slack channels when this dropped was disbelief. Memory corruption, in Java? Isn't memory safety the entire point? This instinct — that the runtime is a fortress and only application code can betray you — is the first failed model, and it's worth examining because it shapes how teams audit their own stacks.
Java-the-language does check every array access and manages every allocation. But Java-the-runtime is an enormous body of C, C++, and assembly. The JIT compilers, the garbage collectors, the intrinsics, the native image code — all of it executes with the full, unmediated power of the process, and none of it enjoys the guarantees it provides to your bytecode. Every intrinsic is a small hole punched through the safety wall in the name of speed, and those holes are maintained by a relative handful of VM engineers. It's the same structural lesson as Alpine Linux's decade-old SSH asterisk bug: the scariest defects live in code everyone depends on and almost nobody reads.
There's a security-audit blind spot here that I see constantly. Teams will fuzz their own JSON parsers, pen-test their REST handlers, and run static analysis across every line they wrote — then treat the JDK as a black box because it's mature, widely deployed, and maintained by smart people. Maturity isn't a defense. It's often the opposite: decades of accumulated optimizations, each one sensible at the time, each one adding attack surface that ships to everyone whether they benefit or not. The Base64 AVX-512 intrinsic exists to accelerate applications decoding enormous volumes of data. Your REST API decoding a 200-byte auth header inherits the risk and gets essentially none of the reward. Calif calls this the tragedy of the commons, and they're right: everyone who needed the feature got the benefit, everyone else just got the bug.
Failed Attempt Two: "The Write Is Too Constrained to Exploit"
The second failed model came from people who read the technical details and relaxed. A constant-value overwrite, at a fixed offset, with no control over the bytes written? Many bugs like that get filed under "crash-only" and deprioritized. That dismissal is understandable and wrong, and the reason it's wrong is the most instructive part of this whole episode.
Modern exploitation isn't about what a single primitive can do; it's about what the surrounding system can be persuaded to arrange around it. Calif's technique was heap grooming — shaping the allocator's behavior remotely so that a predictable, useful object lands right behind the overflown buffer. They did it over the network, using request timing to control when allocations and frees happen on the target. The write may be constant-valued, but if you control which object is sitting in the blast radius, you control what gets corrupted. From there they built a Heartbleed-style memory disclosure, leaked enough to defeat ASLR, and chained into full remote code execution.

There's a deliciously pragmatic detail buried in the write-up about making this work over the real internet. Remote heap grooming is sensitive to round-trip time and jitter — you need requests to arrive in a specific rhythm for the allocator to be in the state you want. Rather than reverse-engineering the TCP stack, the researchers rented a VM in the same cloud region as their target. They solved a physics problem with money. I've seen elite exploit developers do versions of this for years, and it's a good reminder that attacker constraints are economic as much as technical. A well-resourced adversary treats network jitter as a line item.
Also worth noting: there is no universal exploit. Each application — Jira, Jenkins, Keycloak — uses Base64 differently, allocates differently, exposes different grooming surfaces. That's the good news. The bad news is the sheer breadth of entry points. Authentication headers, file upload fields, client certificate handling, message payloads — anywhere Base64 text crosses into the JVM is a potential trigger. One contributor even demonstrated a client-side variant: a Java application that opens a TLS connection to a malicious server can be compromised without exposing any service at all. Your batch jobs and internal tooling are in scope, not just your internet-facing gateways.
The Centaur in the Room: AI Found This in an Hour
Now the part that should recalibrate every security team's threat model. Researcher Quang Luong found the vulnerability in about an hour, and had a working exploit roughly two hours after that. Total AI token cost: under $200. His method was to point an AI coding agent at the areas of HotSpot where complexity crosses boundaries — the JIT, intrinsics, widely reachable APIs, crypto — and then filter the noise. Most of what the agent surfaced was unreachable slop. He kept prompting, and twenty minutes of persistence in, the Base64 finding appeared.
Calif frames this as the "centaur hacker": the human supplies the intuition about where complex systems go wrong, the AI supplies the stamina. I think that's accurate, and I think the implications cut both ways. The same loop that found Java4Shell is available to anyone with an API key, and the exploit-development phase — building reusable grooming pipelines, then letting agents grind out per-application chains — is increasingly automatable. The economics of finding bugs in mature, widely deployed C and assembly just collapsed. Defenders should assume the next dozen Java4Shell-class bugs are already being looked for, by people who don't file disclosures. This is the pressure behind debates like Project Zero's shrinking disclosure deadlines: when discovery gets cheap, the patch window is the whole game.
Calif's proposed countermove is provocative and I mostly agree with it: use the same AI leverage to delete code rather than add it. They call it "vibe-uncoding" — auditing a codebase for dead features, ancient protocol support, and needless optimizations, then ripping them out to shrink attack surface. The honest objection is that deletion is risky: apparently unused features have hidden dependents, and removal needs testing that teams chronically underfund. But the direction is right. If your JDK carries a hand-rolled assembly fast path for a workload you'll never have, the optimal security posture is to not ship that path at all. Barring that, the JVM at least gives you a switch to turn it off. Which brings us to what actually works.
What Actually Works: Patch, Flag, Proxy
Here's the part your on-call rotation cares about. The fixes fall into three tiers, and I'd argue you should be doing at least two of them today, not after the next change window.
- Patch to a fixed OpenJDK build. The upstream fix (JDK commit 5177a70) corrects the mask computation. This is the only complete fix. Affected versions start at 17.0.6 on the 17 line and continue through current releases on 21 and later; check the fixed-in list for your specific train and treat every HotSpot JVM — OpenJDK, Oracle JDK, GraalVM — as in scope until verified otherwise.
- Disable the intrinsic as an interim control. Start the JVM with
-XX:-UseBASE64Intrinsicsto turn off hardware-accelerated Base64 entirely. The performance cost is negligible unless you're decoding gigabytes of Base64, which almost nobody is. Alternatively,-XX:UseAVX=2disables AVX-512 on x86-64 — but do not set that flag on ARM, where the JVM will refuse to start. This is the same philosophy as the PHP CVE playbook: when the vulnerable component is a narrow, replaceable fast path, killing the fast path beats waiting. - Use your proxies to break exploit timing. Calif's own limitations section notes that current remote grooming profiles rely on partial request bodies reaching the application with precise timing. A reverse proxy that buffers the full request body — which nginx does by default — destroys that timing. It is emphatically not a fix, but it meaningfully degrades the most practical attack path while you patch.
Detection deserves a sentence too. Semgrep published free scripts that check for the conjunction of conditions that make a host exploitable: a HotSpot-family VM, x86-64 hardware with the relevant instruction support, and a version in the affected range. Run that across your fleet before you assume you're exposed — your ARM-based containers and OpenJ9 stragglers are fine, and knowing that quickly saves a weekend. When you scan, remember the version lines matter: the fix landed in specific patch releases per train, so "we're on 21" is not an answer.

The Bigger Lesson: Optimizations Are Liabilities You Didn't Audit
Step back from the incident response and Java4Shell leaves an uncomfortable residue. The bug wasn't in some obscure corner feature. It was in Base64 — arguably the most boring, most ubiquitous, most "surely that's fine by now" operation in computing. The vulnerability existed precisely because someone made the boring thing fast, using the newest vector instructions, in assembly, with a tail-handling edge case that survived code review. Every mature runtime is full of these. Every one of them is now being hunted by tireless agents that cost less than a nice dinner.
Everyone is asking what AI can build. The better security question might be what it can help us delete.
My take: the industry is about to learn the difference between code that's audited and code that's assumed safe, and the tuition will be expensive. Standard libraries, VM intrinsics, compression codecs, image decoders — the foundational layers we never question — are exactly where human attention is scarcest and where AI-assisted hunting pays the highest bounties. The centaur model doesn't just find bugs faster; it finds them in places human researchers skipped because the expected value of auditing "solved" code seemed too low.
So patch your JVMs, flip the intrinsic flag where you can't, and let nginx buy you time. But also go look at your own dependency tree and ask the uncoding question: which of these features did we inherit rather than choose? The 65-character string that burns your weekend is probably already written. The only question is whether the person holding it files a disclosure or not.


