Repository navigation
Fix GH-24492: handle base64_encode() soft OOM - #24618
Open
forgeblueai wants to merge 2 commits into
Open
forgeblueai wants to merge 2 commits into
forgeblueai wants to merge 2 commits into
Conversation
This was referenced Oct 23, 2026
Open
Author
|
The latest revision keeps PHP_BASE64_FALLIBLE private to base64.c. The public base64.h header is unchanged, so the existing ABI break label refers to an earlier revision. The revised patch passed 9/9 targeted PHPTs on both NTS and ZTS PHP-8.4 HEAD: https://github.com/forgeblueai/php-core-lab/actions/runs/40005439132 |
forgeblueai
marked this pull request as ready for review
October 23, 2026 19:30
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.
Problem
base64_encode()currently uses the non-falliblephp_base64_encode_ex()allocation contract. A userland call requiring a large output can hit PHP's hard memory limit, terminate with exit 137, and skip the registered shutdown handler. This is part of the previously reported GH-24492 behavior.Fix
Add an internal
PHP_BASE64_FALLIBLEoption used only by the PHPbase64_encode()entry point. Make the five generic and x86 SIMD encoding allocation sites honor that option throughzend_string_safe_falloc(); returnNULLbefore dereferencing the failed allocation. The PHP entry point callsRETURN_OOM().Native C helpers called without the new flag (including existing callers using
PHP_BASE64_NO_PADDING) preserve their non-fallible behavior, avoiding a breaking change to the exported helper contract.Reproduction and tests
The accompanying
ext/standard/tests/url/gh24492_base64_encode_oom.phptconfirms that the input is constructed before invoking Base64, that memory exhaustion is reported through the soft memory-limit fatal path, and that shutdown handlers run.Verified experiments from ForgeBlue PHP Core Lab:
fc05c9bf2486d3d66593501bf78c1d83c32ecbc5.This is deliberately a partial fix. Existing #24548 and #24596 address other allocation paths.
Limits and review notes
Broader PHP test suites, all CPU-selected SIMD implementations, and ARM64-specific validation remain appropriate follow-up work. This patch does not claim a new security vulnerability or CVE.