Describe the bug
In
|
const pretty = stringify(dom, Number.POSITIVE_INFINITY, { |
Infinity is sent as parameter to
stringify and in
|
? stringify(object, Math.floor(maxDepth / 2)) |
the stop condition to the recursion is done by dividing the maxDepth by 2. Considering
Infinity / 2 = Infinity, the code enters in a loop and ends up crashing the page.
Reproduction
Found it in private big project (can only be reproduced if the DOM is large enough to enter the result.length >= MAX_LENGTH check. Maybe we can reproduce it by adding a unit test where we send a really small maxDepth and the whole page as object.
System Info
System:
OS: macOS 15.1.1
CPU: (14) arm64 Apple M3 Max
Memory: 6.47 GB / 36.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
Yarn: 4.6.0 - ~/.nvm/versions/node/v20.12.2/bin/yarn
npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
pnpm: 9.15.2 - ~/.nvm/versions/node/v20.12.2/bin/pnpm
Browsers:
Chrome: 131.0.6778.265
Safari: 18.1.1
Used Package Manager
yarn
Validations
Describe the bug
In
vitest/packages/browser/src/client/tester/public-utils.ts
Line 58 in 345d281
stringifyand invitest/packages/utils/src/display.ts
Line 77 in 345d281
Infinity / 2 = Infinity, the code enters in a loop and ends up crashing the page.Reproduction
Found it in private big project (can only be reproduced if the DOM is large enough to enter the
result.length >= MAX_LENGTHcheck. Maybe we can reproduce it by adding a unit test where we send a really small maxDepth and the whole page as object.System Info
System: OS: macOS 15.1.1 CPU: (14) arm64 Apple M3 Max Memory: 6.47 GB / 36.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node Yarn: 4.6.0 - ~/.nvm/versions/node/v20.12.2/bin/yarn npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm pnpm: 9.15.2 - ~/.nvm/versions/node/v20.12.2/bin/pnpm Browsers: Chrome: 131.0.6778.265 Safari: 18.1.1Used Package Manager
yarn
Validations