util: fix OOM in inspect color stack formatting#64022
Open
Ijtihed wants to merge 1 commit into
Open
Conversation
712033b to
c824e6e
Compare
Author
|
failed the Signed-off-by stuff. could you rerun ci? @mcollina |
Collaborator
BridgeAR
reviewed
Jun 20, 2026
| // Namespaced modules have an extra slash: @namespace/package | ||
| moduleEnd = StringPrototypeIndexOf(line, separator, moduleEnd + 1); | ||
| } | ||
| if (moduleEnd === -1) { |
Member
There was a problem hiding this comment.
Tiny nit: we could make it a nested if statement to have one less comparison
Signed-off-by: Ijtihed Kilani <ijtihedk@gmail.com>
c824e6e to
b478916
Compare
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.
Fixes the heap out-of-memory crash in
util.inspect(err, { colors: true })reported in #64011. Whenerr.stackcontained a frame whosenode_modulespath segment was the final path component with no trailing separator (for exampleat /app/node_modules/foo.js:1:1),markNodeModulesentered an infinite loop so theStringPrototypeIndexOfsearch for the next separator returned-1moduleEndandsearchFromwere set to-1and the nextStringPrototypeIndexOf(line, 'node_modules', -1)restarted the scan from index0which rematched the same segment and growingtempLinewithout bound until the heap was exhausted.The fix clamps
moduleEndtoline.lengthwhen no trailing separator is found sosearchFromadvances past the match and the loop terminates. It also guards the namespaced (@scope) branch against running on a-1indexd which closed a second path into the same loop.Adds a regression test in
test/parallel/test-util-inspect.jswhich asserrts that inspecting an error with such a stack frame returns the expected colorized output instead of hangingFixes #64011