Skip to content

Commit

Permalink
[Fizz Node] Fix null bytes written at text chunk boundaries
Browse files Browse the repository at this point in the history
We encode strings 2048 UTF-8 bytes at a time. If the string we are encoding crosses to the next chunk but the current chunk doesn't fit an integral number of characters, we need to make sure not to send the whole buffer, only the bytes that are actually meaningful.

Fixes #24985. I was able to verify that this fixes the repro shared in the issue (be careful when testing because the null bytes do not show when printed to my terminal, at least). However, I don't see a clear way to add a test for this that will be resilient to small changes in how we encode the markup (since it depends on where specific multibyte characters fall against the 2048-byte boundaries).
  • Loading branch information
sophiebits committed Feb 24, 2023
1 parent ca2cf31 commit 9587b1a
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/react-server/src/ReactServerStreamConfigNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ function writeStringChunk(destination: Destination, stringChunk: string) {
writtenBytes += written;

if (read < stringChunk.length) {
writeToDestination(destination, (currentView: any));
writeToDestination(destination, (currentView: any).subarray(0, writtenBytes));
currentView = new Uint8Array(VIEW_SIZE);
writtenBytes = textEncoder.encodeInto(
stringChunk.slice(read),
// $FlowFixMe[incompatible-call] found when upgrading Flow
currentView,
(currentView: any),
).written;
}

Expand Down

0 comments on commit 9587b1a

Please sign in to comment.