Repository navigation
Return a deep cloned VSBuffer when it might be transferred and then accessed again. - #320190
Closed
er91 (er91) wants to merge 2 commits into
Closed
er91 (er91) wants to merge 2 commits into
er91 (er91) wants to merge 2 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 |
2 of 3 tasks
Member
|
Matt Bierner (@mjbvz) I have a potential smaller change in #321291 |
Author
|
Closing this in favor of #321291 |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
As described in #316841, if a VSBuffer object is transferred to an iframe or a web worker with
window.postMessage()orwebWorker.postMessage(), the backing store of its underlying Uint8Array will be detached. So the next time we call any instance method on the underlying Uint8Array (e.g. subarray()), an error will be thrown. Safari throws an error immediately in this case, while Chrome often does not throw because it detaches the Uint8Array asynchronously.To fix this, we need to return a deep cloned VSBuffer if the return value might be transferred and accessed again in current context. This PR fixes 2 such cases, both in IPC related code (and observed in Safari).
This PR tries to minimize performance penalty by:
Testing
Tested with locally built VSCode server on Linux ARM64, and
Lean 4extension.Without this PR, the
Lean 4extension's InfoView (which is a webview) can only be loaded properly in Chrome; Safari shows an empty webview, with 2 distinct errors in Javascript console:With this PR, the webview can be loaded properly in Safari as well, and the 2 errors disappear.