Fix crash in UTF8ToString with resizable ArrayBuffers#27242
Open
heyparth1 wants to merge 2 commits into
Open
Conversation
sbc100
reviewed
Jul 2, 2026
sbc100
left a comment
Collaborator
There was a problem hiding this comment.
@guybedford this is the kind of thing you warned me about in our last meeting I think.
The fix does seems reasonable. I do wonder if its worth reverting the GROWABLE_ARRAYBUFFERS defaulting to 1 change (#27212) though (in addition to landing this change).
pavelsavara
added a commit
to pavelsavara/emscripten
that referenced
this pull request
Jul 3, 2026
…rayBuffers getUnsharedTextDecoderView now copies data when the heap buffer is resizable (GROWABLE_ARRAYBUFFERS), and the GROWABLE_ARRAYBUFFERS default is reverted to 0 (as in the upstream 6.0.3 fix), so TextDecoder.decode() no longer rejects the view.
guybedford
approved these changes
Jul 3, 2026
guybedford
left a comment
Collaborator
There was a problem hiding this comment.
This makes sense. In the mean time I'd encourage anyone interested in this space to tackle the spec changes to add resizable support to APIs. There's no technical reason not to support resizable buffers short of doing the spec and implementer reach out with regards to ensuring the right security review.
sbc100
reviewed
Jul 3, 2026
| // This settings does nothing unless ALLOW_MEMORY_GROWTH is set. | ||
| // [link] | ||
| var GROWABLE_ARRAYBUFFERS = 1; | ||
| var GROWABLE_ARRAYBUFFERS = 0; |
Collaborator
There was a problem hiding this comment.
Lets make this a separate PR
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.
This fixes a crash in
UTF8ToString(and related functions) that occurs when the heap is backed by a resizableArrayBuffer. TheTextDecoder.decode()API throws aTypeErrorwhen passed a view of a resizableArrayBuffer, which previously caused a crash in builds withALLOW_MEMORY_GROWTHandGROWABLE_ARRAYBUFFERSenabled.The
getUnsharedTextDecoderViewfunction insrc/parseTools.mjsis updated to detect when the heap might be resizable and generate code that copies the data using.slice()if the buffer is resizable, ensuringTextDecoderonly receives non-resizable views. A test is added to verify this behavior by emulating the browser's strictTextDecoderimplementation.Closes #27241