OpenSSL fixes EVP_EncodeBlock() overflow (CVE-2026-121481) with assertions

A pull request in the openssl/openssl repository (#33652) fixes a buffer overflow in EVP_EncodeBlock(), tracked as CVE-2026-121481. The PR description says the OpenSSL SRT has asked for the issue to be fixed publicly and that the advisory is still pending.
The first version of the patch returned -1 for invalid inputs to EVP_EncodeBlock(): NULL input or output buffers, negative lengths, and lengths whose encoded size does not fit in an int. The author, who signs the replies as Nicky, argued this was the most straightforward fix and matched what wolfSSL does in its OpenSSL compatibility layer. The PR also proposed a similar guard for EVP_DecodeBlock(), where no length limit is needed because the decoded length always fits in an int, and a fix for the incorrect length check in base64encode() in http_client.c, which rejected only len > INT_MAX. It added tests in test/base64_dec_avx2_test.c and documented the -1 returns in doc/man3/EVP_EncodeInit.pod.
The PR description also explains how the bug can be reached from the command line: pass a large -proxy_pass to openssl s_client. The author confirmed that GOST accepts such large passwords out of the box. The password has to be supplied through an environment variable (env:VAR), because otherwise the command line is too long. The author notes that the pattern of CVE-2026-121481 is similar to that of CVE-2021-23840.
Reviewers rejected the -1 approach. One asked that call sites check the new return value and named PEM_SignFinal() and NETSCAPE_SPKI_b64_encode() as problem places. Another worried that existing third-party callers, for example ones that cast the return to size_t without checking, would not handle a negative value, and asked for 0 instead. Nicky replied that 0 is a legitimate success value for both functions (EVP_EncodeBlock() returns 0 when dlen == 0, EVP_DecodeBlock() returns 0 for input that is empty after trimming), and that EVP_DecodeBlock() already returns -1 on its failure paths. Another reviewer suggested returning 0 plus an ERR_raise_data. Others said a failure that looks like a success is wrong: STYLE.md says not to add special-case errors like this, the functions should be documented as not accepting negative lengths, and OPENSSL_ASSERT should be used. One reviewer also said the PR adds cases not in the report, called the report's reproducer completely synthetic, and said it probably should not be a CVE without evidence it really happens; they suggested a documentation fix instead. The next comment proposed making a dlen overflow an asserted failure.
Bob-beck wrote that wolfSSL's approach is wrong and dangerous because it adds other problems to solve one that should not exist. Nicky then switched to OPENSSL_assert(). The reasoning, in Nicky's words, was that it avoids breaking existing third-party callers, which do not expect a new error value, and Nicky offered to use ERR_R_PASSED_INVALID_ARGUMENT instead if reviewers preferred. One reviewer had also noted that public functions should put an error on the stack per STYLE.md.
The revised PR description reads: it fixes the overflow in EVP_EncodeBlock() by calling OPENSSL_assert() for inputs that lead to undefined behavior, applies the same fix to EVP_DecodeBlock(), fixes the length check in base64encode() of http_client.c, updates the documentation and adds tests documenting the existing behavior for zero-length inputs.
Several refinements followed. A reviewer pointed out that an empty input passed as f == NULL with dlen == 0 used to work (it wrote the NUL terminator and returned 0), and the author changed the patch to preserve all existing well-defined behavior. For that input the AVX2 path computes src + 0, which is undefined behavior if src is NULL, so the author added handling before the AVX2 path. Later, reviewers said the NULL-pointer asserts were unnecessary: with an early return for dlen == 0, f is read only when dlen > 0, so a NULL pointer would simply crash on first use, and the documented precondition is enough. The author removed them, applied a suggested change to EVP_DecodeBlock() (where -1 is already the documented error return) and added a new test vector.
Bob-beck questioned a "magic computation" in the code and said the internal function, unlike the public API, is free to change: it could return success or failure per STYLE.md, with the length in an output variable. He accepted doing that as a follow-up if a comment with an issue number explained the bound. The author added a short comment on the bound and referenced follow-up issue #33812 so the follow-up does not block the CVE fix. Bob-beck's latest approval said "LGTM if you want to fix my two nits, and land this for now", promising to approve again, and a later comment asked the author to fix the last NULL-check nits, after which the author said both changes were made. Another reviewer, andrewkdinh, noted that backports will require separate PRs.
Key facts
- PR #33652 in openssl/openssl fixes the buffer overflow in EVP_EncodeBlock(), CVE-2026-121481; the OpenSSL SRT asked for a public fix and the advisory is still pending.
- The first patch returned -1 for NULL buffers, negative lengths and lengths whose encoded size does not fit in an int; reviewers objected that this adds a failure that third-party callers may not handle, and that 0 is already a valid success value.
- The revised fix calls OPENSSL_assert() for inputs that lead to undefined behavior, applies the same approach to EVP_DecodeBlock(), and corrects the base64encode() length check in http_client.c, which rejected only len > INT_MAX.
- Reaching the bug from the command line is possible with a large -proxy_pass passed to openssl s_client, with the password supplied via env:VAR; GOST accepts such large passwords out of the box.
- Backports will need separate PRs, and follow-up issue #33812 tracks a cleaner redesign of the internal function.
Why it matters
OpenSSL is among the most widely deployed cryptographic libraries, and EVP_EncodeBlock() is a public base64 encoding function. A buffer overflow there has been given a CVE, and the author says its pattern is similar to CVE-2021-23840. The thread also shows how the maintainers choose to handle a public function whose invalid inputs previously led to undefined behavior: not by adding a new error value, but by asserting.
Who it affects
Applications that call EVP_EncodeBlock() or EVP_DecodeBlock() with large or invalid lengths are the ones in scope. Reviewers were concerned about third-party callers that cast the return value to size_t without checking it, which is why a new negative return was rejected. The PR also touches the base64encode() function in http_client.c, reachable by passing a large -proxy_pass to openssl s_client. Maintainers of branches that need the fix should note that backports will require separate PRs.
How to use it
There is nothing to install from this thread. Anyone tracking the issue can follow PR #33652 and the pending advisory from the OpenSSL project. The PR also updates doc/man3/EVP_EncodeInit.pod and adds tests, including in test/base64_dec_avx2_test.c. Code that calls these functions should avoid passing negative lengths or lengths whose encoded size does not fit in an int, since the revised fix asserts on such inputs.
How solid is it
The source is the first-party OpenSSL pull request itself, so the code discussion and the reviewers' comments are direct. The text shown covers the conversation up to a reviewer saying to fix the nits and land the change, and does not say whether the PR has been merged. The advisory is still pending, and no affected or fixed release numbers are given.
Risks and caveats
One reviewer called the report's reproducer completely synthetic and said it probably should not be a CVE without evidence it really happens, suggesting a documentation fix instead. Using OPENSSL_assert() means that invalid inputs abort the process rather than return an error. The author's earlier -1 approach was dropped partly because it could break callers that do not expect a negative value. The source gives no evidence of exploitation in the wild, and the shown text is truncated, so later discussion and the diff itself are not visible.
“Note for our fixer: Just because Wolf does it doesn't mean it's right.”
— bob-beck, reviewer on openssl/openssl PR #33652