Repository navigation
Fix infinite loop on allocation failure in unicode_script() - #1829
Merged
saghul merged 1 commit intoOct 18, 2026
Merged
Conversation
bnoordhuis
reviewed
Oct 17, 2026
bnoordhuis
left a comment
Contributor
There was a problem hiding this comment.
You can drop the test, this bug is small enough it doesn't need one. LGTM apart from that.
The fail label in unicode_script() ended with `goto fail;`, so any
allocation failure sent the function back into its own cleanup handler
forever. On the Script= path (is_ext=0) that is a non-returning spin; on
the Script_Extensions= path (is_ext=1) each iteration calls cr_free() on
cr1 and cr2 again, and cr_free() does not clear points, so the same
buffer is freed repeatedly.
Reachable from regexp compilation: /\p{sc=Latin}/u and /\p{scx=Latin}/u
run unicode_script() via parse_unicode_property(), so a RegExp compiled
under a memory limit can hang or abort on a double free.
Return -1 from the fail label instead. cr_free() still runs once on
every failing is_ext path, the -2 unknown-script return is unaffected,
and the success path still frees cr1/cr2 exactly once.
Kayyo321
force-pushed
the
fix/unicode-script-alloc-failure-loop
branch
from
October 18, 2026 02:29
b8bb367 to
92d804d
Compare
Contributor
Author
|
Thanks, dropped the test & removed that from the PR desc. |
saghul
approved these changes
Oct 18, 2026
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.
unicode_script()ended its fail label withgoto fail;, so any allocation failure looped back into the cleanup handler instead of returning. For\p{sc=...}(is_ext=0) it never returns; for\p{scx=...}(is_ext=1) each pass callscr_free(cr1)andcr_free(cr2)again, andcr_free()does not clearpoints, so the same buffer is freed repeatedly. It is reached from RegExp compilation viaparse_unicode_property(), sonew RegExp('\p{scx=Latin}', 'u')compiled under a memory limit (~110k on this build) aborts on glibc double-free detection.Return
-1from the fail label.cr_free()still runs once on each failing is_ext path; the-2"not found" return and the success path (which freescr1/cr2once) are unchanged.lre-test,api-test, andrun-test262 -c tests.conf(0/120 errors) pass. test262 proper was not run here (submodule not checked out).Fixes #1828
🤖 Generated with Claude Code