Bun.Transpiler: fix use-after-free in async transform() error messages#30442
Closed
robobun wants to merge 1 commit into
Closed
Bun.Transpiler: fix use-after-free in async transform() error messages#30442robobun wants to merge 1 commit into
robobun wants to merge 1 commit into
Conversation
…m() returns error
Collaborator
Author
Contributor
Contributor
|
Found 1 issue this PR may fix:
🤖 Generated with Claude Code |
Contributor
|
This PR may be a duplicate of:
🤖 Generated with Claude Code |
Collaborator
Author
|
Duplicate of #29958. |
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.
What does this PR do?
Fixes a use-after-free in
Bun.Transpiler.prototype.transform()(the async variant) when the input fails to parse.TransformTask.run()executes on a worker thread and uses a thread-localMimallocArenafor parsing. The lexer allocates error message text (e.g."Unexpected \x00") from this arena viastd.fmt.allocPrint(self.allocator, ...). The arena is destroyed whenrun()returns, but the log messages that reference that text are read later on the main thread inthen()→log.toJS()→Msg.clone(), whichmemcpys from the freed arena.Under ASAN this shows up as
use-after-poison; in release builds it reads stale/garbage bytes and can manifest as other signals depending on what reuses the arena pages.Fix: before
run()returns (and beforearena.deinit()runs), deep-clone each log message intobun.default_allocatorso the text, location, and notes all outlive the arena.Msg.clone()already deep-clonesdata.text,location.file,location.line_text, and each note'sDataviabun.clone.How did you verify your code works?
Minimal repro that crashes the ASAN build before this change and passes after:
Added as
test/js/bun/transpiler/transpiler-async-error-uaf.test.ts, which also asserts the error message content is preserved correctly. All existingtest/js/bun/transpiler/tests pass.Found by Fuzzilli (fingerprint
11673762e644e33d).