Conversation
Builtin C functions are defined as auto-init properties and created on their first access. When that setup failed, JS_AutoInitProperty() had already turned the property into a plain data property holding undefined, so the builtin stayed undefined for the rest of the context's life: after an out-of-memory error on the first access of JSON.parse, typeof JSON.parse was "undefined" even once memory was available again. Check for the exception before converting the property, so that the next access runs the setup again. The setup function does not modify the object's properties, so there is nothing to undo.
This branch has not been deployed
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.
Builtin C functions (
JS_DEF_CFUNCentries) are defined as auto-init properties and created on their first access. When that setup fails,JS_AutoInitProperty()has already turned the property into a plain data property holdingundefined, so it staysundefinedfor the rest of the context's life:With a memory limit, a first access that runs out of memory therefore breaks the builtin in that context even after memory is available again. For
JSON.parse:On
master, setting the limit a few bytes above the current usage and raising it 4 bytes at a time, 39 of 1025 fresh contexts ended up like that.This returns before converting the property when
funcfails, so the next access runs the setup again.funcdoes not modify the object's properties, so there is nothing to undo.Test
autoinit_after_failureinapi-test.ccompilesJSON.parsefirst, then runs it with the limit a few bytes above the current usage, raised 8 bytes at a time until it succeeds, and checks after each attempt thattypeof JSON.parseis"function". Compiling beforehand keeps the parser out of the low-memory part, so only the property access is exercised. The test fails onmasterwith and without sanitizers and passes with this change; it usesnew_runtime(), so these paths are also checked for leaks.make test(0/117 errors),make cxxtestand the wholeapi-testpass.