Skip to content

Commit 2d7b743

Browse files
committed
add tests to exercise codepaths dealing with buffer overlows
1 parent 3ae6dea commit 2d7b743

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

packages/react-dom/src/__tests__/ReactDOMFizzServerBrowser-test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,44 @@ describe('ReactDOMFizzServer', () => {
248248
expect(rendered).toBe(false);
249249
expect(isComplete).toBe(true);
250250
});
251+
252+
// @gate experimental
253+
it('should stream large contents that might overlow individual buffers', async () => {
254+
const str492 = `(492) This string is intentionally 492 bytes long because we want to make sure we process chunks that will overflow buffer boundaries. It will repeat to fill out the bytes required (inclusive of this prompt):: foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux q :: total count (492)`;
255+
const str2049 = `(2049) This string is intentionally 2049 bytes long because we want to make sure we process chunks that will overflow buffer boundaries. It will repeat to fill out the bytes required (inclusive of this prompt):: foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy thud foo bar qux quux corge grault garply waldo fred plugh xyzzy :: total count (2049)`;
256+
257+
// this specific layout is somewhat contrived to exercise the landing on
258+
// an exact view boundary. it's not critical to test this edge case but
259+
// since we are setting up a test in general for larger chunks I contrived it
260+
// as such for now. I don't think it needs to be maintained if in the future
261+
// the view sizes change or become dynamic becasue of the use of byobRequest
262+
let stream;
263+
stream = await ReactDOMFizzServer.renderToReadableStream(
264+
<>
265+
<div>
266+
<span>{''}</span>
267+
</div>
268+
<div>{str492}</div>
269+
<div>{str492}</div>
270+
</>,
271+
);
272+
273+
let result;
274+
result = await readResult(stream);
275+
expect(result).toMatchInlineSnapshot(
276+
`"<div><span></span></div><div>${str492}</div><div>${str492}</div>"`,
277+
);
278+
279+
// this size 2049 was chosen to be a couple base 2 orders larger than the current view
280+
// size. if the size changes in the future hopefully this will still exercise
281+
// a chunk that is too large for the view size.
282+
stream = await ReactDOMFizzServer.renderToReadableStream(
283+
<>
284+
<div>{str2049}</div>
285+
</>,
286+
);
287+
288+
result = await readResult(stream);
289+
expect(result).toMatchInlineSnapshot(`"<div>${str2049}</div>"`);
290+
});
251291
});

0 commit comments

Comments
 (0)