CVE-2026-121481: OpenSSL EVP_EncodeBlock() Heap Overflow, Affected Versions and the Assertion Fix

The CyberSec Guru

CVE-2026-121481: OpenSSL EVP_EncodeBlock() Heap Overflow

If you like this post, then please share it:

Buy me A Coffee!

Support The CyberSec Guru’s Mission

🔐 Fuel the cybersecurity crusade by buying me a coffee! Why your support matters: Zero paywalls: Keep the main content 100% free for learners worldwide.

“Your coffee keeps the servers running and the knowledge flowing in our fight against cybercrime.”☕ Support My Work

Buy Me a Coffee Button

On 18 November 2026 the OpenSSL project, acting as its own CVE numbering authority, published CVE-2026-121481. The description is a single sentence: calling EVP_EncodeBlock() with an input length close to INT_MAX may overflow the calculation of the encoded output size and write past the end of the caller-supplied output buffer. A day later CISA’s ADP enrichment attached a CVSS 3.1 base score of 9.8 (Critical) with the vector AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H, and GitHub advisory GHSA-83XJ-7XH4-4P7X mirrored the score.

The headline number travelled fast. The mechanics travelled slower, which is a pity, because they are the better story. The bug is a piece of signed-integer arithmetic that has sat in a public API since the SSLeay era, and the fix that won approval is an assertion instead of a new error code.

CVE-2026-121481 at a glance: affected OpenSSL versions and fix status

Two facts need stating up front, because most early coverage got them wrong.

The first is scope. The CNA record lists exactly two affected ranges: 4.0.0 up to but not including 4.0.4, and 4.1.0 up to but not including 4.1.1. Everything else defaults to “unaffected”. In shipped software that means the 4.0 branch from 4.0.0 through 4.0.3, plus 4.1.0. OpenSSL 3.x is outside the affected set.

The second is timing. As of 20 November 2026 there is no fixed release to download. The fix lives in public pull request , and the releases that will carry it, 4.0.4 and 4.1.1, are scheduled for 1 December 2026 alongside the fixes from the 10 November and 17 November advisories. “Upgrade to 4.0.4 or 4.1.1” is correct advice about a version that does not exist yet. Until it ships, the only complete mitigation is to keep enormous lengths away from the function.

Why EVP_EncodeBlock() overflows: an int-sized API contract

EVP_EncodeBlock() is the one-shot base64 encoder in OpenSSL’s EVP layer. Its signature, from the manual page, is int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n). It reads n bytes from f, writes base64 into t, appends a NUL terminator, and returns the number of encoded bytes excluding that terminator. The documentation’s own example: 16 bytes of input produce 24 bytes of base64 plus one NUL, 25 bytes in total, and the function returns 24. Every three input bytes become four output bytes, with = padding when the input is not a multiple of three. The caller allocates t. The function is told nothing about how large t actually is, and that is where the trouble starts.

The length parameter is a signed int, and so is the return value. This is an inherited design. The EVP base64 routines descend from a codebase that predates the widespread use of size_t for buffer sizes, and the one-shot block functions kept the old shape while the rest of the library modernised.

The streaming sibling, EVP_EncodeUpdate(), works in 48-byte input blocks that become 64 base64 characters plus a newline. It picked up enough hardening over the years that current master checks if (total > INT_MAX) and fails the call by setting *outl to 0 and returning 0. The one-shot EVP_EncodeBlock() never got an equivalent guard.

In the 4.x source it dispatches to an AVX2 encoder when the CPU supports it, and to an internal scalar helper otherwise. Both paths treat the result the same way: they cast the internal size_t length down to int and return it. The internal helpers compute in size_t and write the correct number of bytes. The public wrapper then squeezes that length back into a type that cannot always hold it.

EVP_ENCODE_LENGTH: safe in 4.x, risky in 3.x and earlier

The sizing macro is a place where intuition from older OpenSSL versions misleads. EVP_ENCODE_LENGTH(l), the helper callers use to size output buffers, is defined in current master as (((((size_t)(l)) + 2) / 3 * 4) + ((((size_t)(l)) / 48 + 1) * 2 + 80). The cast to size_t happens before the arithmetic, so on a 64-bit platform the macro does not overflow for an int-sized input. The (l/48+1)*2 term reserves room for the line breaks the streaming encoder inserts, and the trailing 80 is slack.

📬 Stay Ahead of Cyber Threats

Get the latest cybersecurity news, critical vulnerabilities, threat intelligence, tutorials, and exclusive giveaways delivered straight to your inbox. No spam. Unsubscribe anytime.

In OpenSSL 3.x and earlier, the same macro performed its arithmetic in the type of its argument, so a signed int argument could overflow inside the macro. That older behaviour is the source of a widely circulated worked example, and it is not what happens in the affected 4.x code. In 4.x the macro is safe. What remains unsafe is the int return value of EVP_EncodeBlock() itself, and any caller that does its own output-size arithmetic in int instead of reaching for the macro. The HTTP client’s base64 helper, covered below, is exactly such a caller.

The INT_MAX math: where base64 output stops fitting in an int

Base64’s four-thirds expansion gives a clean boundary. The encoded length is 4 * ceil(n / 3), and that fits in a signed 32-bit int only while ceil(n / 3) is at most INT_MAX / 4, which is 536,870,911. The largest input satisfying this is n = (INT_MAX / 4) * 3 = 1,610,612,733. At that input the encoder produces 2,147,483,644 bytes, or 2,147,483,645 with the NUL terminator, still inside INT_MAX (2,147,483,647). One more input byte pushes the encoded length to 2,147,483,648, which does not fit. This is the bound the fix asserts, and it is tight: the exact last input whose output the return type can represent, with no round number picked for comfort.

The INT_MAX boundary: Where Base64 encoding breaks
The INT_MAX boundary: Where Base64 encoding breaks

Past that boundary two things go wrong in two different places.

Inside EVP_EncodeBlock(), the cast of the internal size_t length to int is a signed overflow, which the C standard leaves undefined. On the two’s-complement targets everyone actually ships, it wraps to a negative number, so the function reports a nonsensical length while having written the full, correct output.

Outside the function, a caller that computed its buffer size in int arithmetic gets a wrapped, far-too-small value and allocates too little. The function then writes the real output past the end of that buffer. The result is a heap overflow, which is why CISA’s enrichment tags it CWE-122 and the matching attack pattern CAPEC-92.

A worked example at INT_MAX minus one

Take n = INT_MAX - 1 = 2,147,483,646. The true encoded payload is 2,863,311,528 bytes, roughly 2.86 gigabytes, plus the NUL. A caller that computes (n + 2) / 3 * 4 in a 32-bit int watches n + 2 wrap to -2,147,483,648, the division yield -715,827,882, and the multiplication wrap again to 1,431,655,768, roughly 1.43 gigabytes. It allocates about half of what it needs. EVP_EncodeBlock() then writes 2.86 gigabytes into a 1.43-gigabyte buffer and overruns it by about 1.43 gigabytes.

The arithmetic is deterministic. There is no race and no malformed input to parse, only a length the type system cannot carry. Because the overflow is undefined behaviour rather than a defined wrap, a compiler is also entitled to assume it never happens and optimise accordingly. That is the usual reason these bugs survive code review and surface only under sanitizers or at the extremes.

How the heap buffer overflow actually happens
How the heap buffer overflow actually happens

Why EVP_DecodeBlock() has no length overflow

The decode side escapes this problem, and the asymmetry is instructive. EVP_DecodeBlock() contracts data: every four input bytes yield three output bytes, so even an INT_MAX-sized input decodes to at most 3 * (INT_MAX / 4) = 1,610,612,733 bytes, comfortably inside int. No length overflow is possible.

Its real edge cases are null pointers and negative lengths, plus some long-documented quirks. It trims leading and trailing whitespace, requires the trimmed length to be a multiple of four, returns -1 on error, and does not subtract padding from the returned length. That is why the fix treats the two functions differently, and why the decode guard ended up as an ordinary early return instead of an assertion.

How openssl s_client and a 2 GB proxy password trigger the heap overflow

The reproducer in the pull request is specific enough to reconstruct. openssl s_client can tunnel through an HTTP proxy with -proxy, and it authenticates to that proxy with a Proxy-Authorization: Basic header built by base64-encoding user:password. The password can come from -proxy_pass, which accepts the usual OpenSSL password sources, including env:VAR to read it from an environment variable at runtime.

The base64 encoding happens in a helper named base64encode() in http_client.c, and that helper’s length check rejected only len > INT_MAX. On a platform where len is held in a type that can represent values up to INT_MAX, the check passes for a password of, say, 1.7 gigabytes, even though the encoded size of such a password overflows an int. The helper sizes its output buffer with the wrapped value, calls EVP_EncodeBlock(), and the encoder writes past the allocation.

The password has to arrive through env:VAR because operating systems cap the size of a single argument string. On Linux, MAX_ARG_STRLEN limits each argv or envp string passed at execve time to 32 pages, 128 kilobytes on a typical configuration, so a gigabyte-scale password cannot be handed to a program as a literal argument at all. Reading it from the environment at runtime sidesteps that limit.

The pull request author, Nicky Mouha, reported that the Go-based tunneling proxy gost (GO Simple Tunnel) accepts such oversized passwords out of the box, which let the demonstration run end to end against a real peer. Keep the roles straight: gost is the proxy on the other end, written in Go and not linked against OpenSSL. The memory corruption happens in the OpenSSL client process that does the encoding.

Is the CVE-2026-121481 CVSS 9.8 score justified?

This is where the severity argument lives. Bob Beck, reviewing the patch, called the report’s reproducer “completely synthetic” and suggested it “probably should not be a CVE without evidence it really happens”, proposing a documentation fix instead. On the facts, he has a point. The overflow occurs in whichever process is persuaded to encode a near-INT_MAX buffer in a single call, and in the demonstration that process is a command-line client whose operator chose to supply a two-gigabyte password.

Nothing here lets a remote attacker overflow a TLS server with a clever handshake. TLS does not base64-encode protocol messages, and the certificate and PEM paths that use the EVP encoder inside OpenSSL pass small, bounded DER structures. For a server to be hit, an application would have to take attacker-controlled data, buffer gigabytes of it in memory, and hand the whole length to EVP_EncodeBlock() while sizing the destination in int. That pattern exists in some base64-encoding services and import pipelines. It is not the default posture of most software linked against OpenSSL.

The score reflects the worst case the API permits and no demonstrated attack. CISA’s SSVC assessment records exploitation as “none”, automatable as “yes”, and technical impact as “total”. The CVSS network vector describes the reachability of a vulnerable caller, with OpenSSL itself out of the picture. OpenSSL’s own CNA record carries no CVSS score, the project’s tracker labels the pull request “severity: important”, and third-party aggregators that read only the CNA container report the severity as unknown.

The independent cve.now index weights observed exploitation and confirmed exposure more heavily than raw CVSS. It gives the CVE a provisional 50 out of 100: full marks for reach and technical severity, zero for exploitation signal, with a note that the advisories do not say whether default configurations are exposed. It estimates the score would rise to about 95 if the CVE joined CISA’s KEV catalog, and to about 55 if advisories confirmed default setups are affected. As of 19 November there is no known exploitation and no KEV entry.

The fair reading: 9.8 describes a contract that can fail catastrophically when misused at extreme sizes, while the population of deployments actually exposed is narrow and, on the published record, unquantified.

The EVP_EncodeBlock() fix: why OpenSSL chose an assertion over an error code

The first patch returned -1

The first version of the fix, pushed on 11 November, did the obvious thing. It made EVP_EncodeBlock() return -1 for invalid inputs: null output or input buffers, negative lengths, and lengths whose encoded size does not fit in an int. Mouha added a matching guard to EVP_DecodeBlock(), corrected the len > INT_MAX check in http_client.c, updated doc/man3/EVP_EncodeInit.pod, and added tests in test/base64_dec_avx2_test.c.

Returning -1 matched what wolfSSL’s OpenSSL compatibility layer already does. The OpenSSL Security Response Team had asked for the fix to be handled publicly instead of through the private security process, which is why the work happened in an open pull request labelled NSF with the advisory still pending.

Why -1 and 0 were both rejected

Review then turned into a small seminar on what it means to add failure to an API that was never designed to fail.

The reviewer jogme asked whether call sites that ignore the return value had been audited, naming PEM_SignFinal() and NETSCAPE_SPKI_b64_encode(). Tomáš Mráz (t8m) agreed those callers should be checked but doubted they could plausibly trigger the new error, since they encode small structures, and asked that any audit be a separate commit. He then raised the concern that shaped everything after it: existing third-party callers might cast the return value to size_t without checking, in which case -1 becomes SIZE_MAX and a failure reads as an astronomically large success.

Neil Horman (nhorman) suggested returning 0 instead. The documentation defines the return as the number of bytes encoded, so zero accurately describes a failed encoding, with an ERR_raise_data to record the reason.

Mouha countered that both functions can already return 0 legitimately. EVP_EncodeBlock() returns 0 for an empty input, and EVP_DecodeBlock() returns 0 when the input is empty after trimming. EVP_DecodeBlock() also already uses -1 for its existing error paths, such as a trimmed length that is not a multiple of four or invalid base64 characters. Making 0 an error signal for the encoder while the decoder keeps -1, or changing the decoder’s -1 errors to 0, would leave callers worse off than a consistent -1.

Beck settled the direction by invoking the project’s STYLE.md, which says not to introduce special-case errors where a failure looks like a success. Zero is a success case. A magic value that resembles success adds dead code and untested error paths across the ecosystem. The function should document that it does not accept negative or oversized lengths, and assert the precondition. “Just because Wolf does it doesn’t mean it’s right,” he added, of the wolfSSL precedent.

Eugene Syromiatnikov (esyr) went further and called the API itself broken. He suggested it write only the NUL and return 0 when the expected output exceeds INT_MAX, be deprecated, and be replaced by an EVP_EncodeBlock_ex() with a saner contract.

What landed: two assertions and a follow-up issue

The approved resolution was narrower than any of those proposals, deliberately. For inputs that previously invoked undefined behaviour, EVP_EncodeBlock() now asserts the documented precondition instead of returning a new error value. The landed guards are an assertion that dlen >= 0 and an assertion that dlen <= (INT_MAX / 4) * 3, with a comment explaining the bound and a reference to follow-up issue . That issue tracks moving the overflow check into the internal helpers, where STYLE.md permits a proper success/failure return with the length passed through an output parameter. The internal helpers can be changed freely. The public wrapper cannot.

Before vs. after: Why OpenSSL chose assertions
Before vs. after: Why OpenSSL chose assertions

There was precedent in the same file: EVP_DecodeUpdate() already uses OPENSSL_assert(n < (int)sizeof(ctx->enc_data)). The assertion turns silent heap corruption into a loud, immediate abort and changes nothing for any caller that was already behaving correctly.

Edge cases that almost broke existing callers

“Preserve all existing well-defined behaviour” is a stricter requirement than it sounds, and it ate most of the remaining effort.

Beck caught that the initial null check rejected an empty input passed as f == NULL with dlen == 0. That call historically worked: it wrote the NUL terminator and returned 0. An application encoding an empty buffer it never allocated would suddenly have received an error. The fix preserves the call. Mouha noted a subtlety: the AVX2 path computes src + 0, which is itself undefined behaviour when src is null, so the empty case has to be handled before the vector path is entered.

Beck then argued that the explicit t != NULL and f != NULL assertions were unnecessary, since a null pointer crashes on first use anyway and the documented precondition is enough. Those assertions were removed.

For the decoder, Andrew Dinh (andrewkdinh) suggested replacing the assertions with if (n <= 0) return n == 0 ? 0 : -1;. Mouha applied it along with a new test vector, because -1 is already the documented error return for EVP_DecodeBlock() and no new failure semantics are introduced. Beck gave his LGTM, andrewkdinh approved on 19 November, and the backports to the 4.0 and 4.1 branches need separate pull requests. The earlier draft follow-up, , which would have audited call sites for the new error return, became unnecessary once the design stopped returning a new error.

The trade-off

An assertion suits a precondition violation the caller should never have produced. It is the wrong tool for a runtime condition an application might legitimately want to handle. The maintainers knew this and deferred the cleaner design, an internal refactor and possibly a new _ex entry point, so the CVE fix would not wait on an API redesign. The assertion closes the hole without breaking the thousands of callers that cast the return value and move on.

How to mitigate CVE-2026-121481 before OpenSSL 4.0.4 and 4.1.1 ship

Before 1 December 2026

There is no fixed release, so the mitigation is to keep dangerous inputs away from the function. Enforce application-level length limits on anything that flows into a one-shot base64 encode, and treat a credential, header, or blob measured in gigabytes as a bug in its own right, CVE or no CVE. Building from the public git tree once the fix and its backports land is an option for those who cannot wait. The supported path is the scheduled 4.0.4 and 4.1.1 releases.

After the releases ship

Upgrading is the fix, but read it as hardening and not as a graceful-failure guarantee. The assertion aborts the process on an oversized input. It does not return an error an application can catch. Code that needs to survive bad input must still impose its own limits before calling.

Auditing your call sites

The audit that matters is at the call sites. Check any code that passes externally influenced lengths into EVP_EncodeBlock() and sizes the destination with int arithmetic, because that is the pattern that turns the wrapped return value into a heap overflow. The http_client.c helper is the confirmed instance, and its corrected length check is part of the same pull request.

Callers that size buffers with the size_t-casting EVP_ENCODE_LENGTH macro are in better shape on the allocation side, but they still receive a wrapped int return for oversized inputs and should not trust it. The general discipline: do not cast a signed int return to size_t without checking it, do not assume a buffer-size computation fits the type it is written in, and check the return values of functions documented to fail. The internal OpenSSL callers jogme flagged, PEM_SignFinal() and NETSCAPE_SPKI_b64_encode(), encode small bounded structures and are not plausibly reachable at these sizes, which is why Mráz was comfortable deferring their audit.

CVE-2021-23840 vs CVE-2026-121481: the same int-sized API problem, five years apart

OpenSSL has been here before. CVE-2021-23840, disclosed on 16 February 2021, was an integer overflow in EVP_CipherUpdate(), EVP_EncryptUpdate() and EVP_DecryptUpdate(). With an input length close to the maximum permissible integer, the output length argument could overflow, the function would return 1 for success, and the output length would be negative. Paul Kehrer reported it and Matt Caswell fixed it in 1.1.1j and 1.0.2y. OpenSSL’s own severity policy rated it Low, while NVD scored it 7.5.

The root cause belongs to the same family: a public API that communicates buffer sizes through signed int, combined with arithmetic that assumes those sizes stay far from the type’s upper bound. The 2021 fix added explicit length checks and documented the maximum supported input. The 2026 fix follows the same philosophy, but because the encoder’s return value cannot carry a new error without breaking callers, it lands as an assertion instead of a check that returns failure. The library is still negotiating the same retrofit: how to make an old, int-typed, success-only contract fail safely without breaking the ecosystem that grew up around it.

What the CVE-2026-121481 fix leaves open

The arithmetic can be verified on paper. The trigger is narrow enough that the project’s own reviewers questioned whether it deserved a CVE. The fix fits in a handful of lines. What took the effort was deciding what those lines should do on bad input, in a codebase where the style guide, the compatibility promises, and twenty-five-year-old function signatures all pull in different directions.

The assertion that landed converts undefined behaviour into a defined, visible stop and leaves every well-defined call exactly as it was. A library can be mathematically sound while a single signed multiplication writes a gigabyte past the end of a heap allocation. The cleaner design, an encoding API that reports failure through a channel separate from its success value, is still owed, and issue is the marker left in the code to keep it from being forgotten.

FAQ: CVE-2026-121481 and OpenSSL EVP_EncodeBlock()

What is CVE-2026-121481?

An integer overflow in OpenSSL’s EVP_EncodeBlock(). With an input length near INT_MAX, the encoded output size overflows a signed int and the function can write past the end of a caller-supplied buffer, a heap overflow classified as CWE-122.

Which OpenSSL versions are affected by CVE-2026-121481?

OpenSSL 4.0.0 through 4.0.3, and 4.1.0. The CNA record lists the ranges as 4.0.0 up to but not including 4.0.4, and 4.1.0 up to but not including 4.1.1. OpenSSL 3.x is not in the affected set.

Is there a patch for CVE-2026-121481 yet?

As of 20 November 2026 there is no released fix. The fix is in public pull request , which is approved, and it will ship in OpenSSL 4.0.4 and 4.1.1 on 1 December 2026.

Does CVE-2026-121481 let an attacker exploit a TLS server remotely?

Nothing in the published analysis shows that. TLS does not base64-encode protocol messages, and OpenSSL’s internal PEM and certificate paths encode small bounded structures. A server is exposed only if an application buffers gigabytes of attacker-controlled data and passes the whole length to EVP_EncodeBlock() while sizing the buffer in int.

Is CVE-2026-121481 being exploited in the wild?

No known exploitation, and no CISA KEV entry as of 19 November 2026. CISA’s SSVC assessment records exploitation as “none”.

What does the OpenSSL fix actually do?

It asserts the documented precondition: the length must be non-negative and no greater than (INT_MAX / 4) * 3, which is 1,610,612,733. An oversized input aborts the process and no longer corrupts the heap. EVP_DecodeBlock() instead gets an ordinary early return, since it already uses -1 as its error value.

Buy me A Coffee!

Support The CyberSec Guru’s Mission

🔐 Fuel the cybersecurity crusade by buying me a coffee! Your contribution powers free tutorials, hands-on labs, and security resources.

Why your support matters:
  • Writeup Access: Get complete writeup access within 12 hours
  • Zero paywalls: Keep the main content 100% free for learners worldwide

Perks for one-time supporters:
☕️ $5: Shoutout in Buy Me a Coffee
🛡️ $8: Fast-track Access to Live Webinars
💻 $10: Vote on future tutorial topics + exclusive AMA access

“Your coffee keeps the servers running and the knowledge flowing in our fight against cybercrime.”☕ Support My Work

Buy Me a Coffee Button

If you like this post, then please share it:

Exploits

Discover more from The CyberSec Guru

Subscribe to get the latest posts sent to your email!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.