Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite loop: module.exports alias detection #31436

Merged
merged 3 commits into from May 17, 2019

Conversation

sandersn
Copy link
Member

Previously, module.exports alias detection in the binder could enter an
infinite recursion. Now it does not.

Notably, there are two safeguards: a counter limiter that I set at
100, and an already-seen set. I actually prefer the counter limiter code
because it's foolproof and uses less memory. But it takes 100
iterations to escape from loops.

I want to only keep one safeguard. Opinions? Should I reduce the number of allowed iterations?

Fixes #31094

Previously, module.exports alias detection in the binder could enter an
infinite recursion. Now it does not.

Notably, there are *two* safeguards: a counter limiter that I set at
100, and an already-seen set. I actually prefer the counter limiter code
because it's foolproof and uses less memory. But it takes 100
iterations to escape from loops.
@sandersn
Copy link
Member Author

I decided on the counter-based limit since it uses less memory and is just as fast in the common case. It's also dead simple.

@rbuckton
Copy link
Member

@sandersn: You could set a NodeFlag or some other bit as you start to check the node, exit if the bit is already set, and unset the bit when you exit the function (so that it is unset if the node is reused in incremental parse).

@sandersn
Copy link
Member Author

@rbuckton reusing existing memory is really clever! I do like the simplicity of a counter though, so I think I'll stick with that.

@sandersn sandersn merged commit eeba30a into master May 17, 2019
@sandersn sandersn deleted the fix-infinite-loop-module-exports-alias branch May 17, 2019 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

export assignment causes infinite recursion in binder
3 participants