Return a deep cloned VSBuffer when it might be accessed again.#320190
Open
er91 wants to merge 6 commits into
Open
Return a deep cloned VSBuffer when it might be accessed again.#320190er91 wants to merge 6 commits into
er91 wants to merge 6 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR hardens ChunkStream._read() against a scenario where callers transfer returned VSBuffers (e.g., via window.postMessage()), which can detach underlying buffers and make the stream’s retained chunks inaccessible.
Changes:
- Documented why
_read()sometimes needs to return deep clones instead of references/views. - Updated
_read()fast paths to return clones whenadvance === falseand returning data that aliases an internal chunk. - Added cloning in additional branches to avoid returning buffers that could be transferred while still needed internally.
Comments suppressed due to low confidence (1)
src/vs/base/parts/ipc/common/ipc.net.ts:207
- The new comment explains callers may transfer the returned
VSBuffer. Returning a shared singleton fromgetEmptyBuffer()means a transfer could detach that shared underlying buffer and affect subsequent callers. Consider returning a fresh empty buffer (or a clone) here to avoid shared-state detachment.
if (byteCount === 0) {
return getEmptyBuffer();
}
Author
|
@microsoft-github-policy-service agree |
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.
Context
Fixes #316841
Summary
Returned VSBuffer object of
ChunkStream._read()might be used inwindow.postMessage()and be transferred to an iframe, and become inaccessible in the current window. As a result, next time we try to access the same VSBuffer object, Safari will throw an exception synchronously.In self-hosted
code serve-web, this will cause extension webview to fail to load. Chrome/V8 is more relaxed and does not throw any exception in this case.This PR makes sure to return a deep cloned VSBuffer object if it might be accessed again.