Title: stream: fix decoded fromList chunk boundary check by watson · Pull Request #61884 · nodejs/node · GitHub
Open Graph Title: stream: fix decoded fromList chunk boundary check by watson · Pull Request #61884 · nodejs/node
X Title: stream: fix decoded fromList chunk boundary check by watson · Pull Request #61884 · nodejs/node
Description: Correct fromList() in decoded string mode to compare n against the current chunk length, not the buffer array length.
This prevents over-consuming chunks, which can corrupt readable state and crash with TypeError when mixing setEncoding() and read(n).
I reproduced this in all non-EoL release lines.
For reference, here's the script I used to make read() throw (usually it throws almost instantly, but a few times it can take a little while):
'use strict'
const https = require('node:https')
const url = process.argv[2] || 'https://www.google.com'
const maxRuns = Number(process.argv[3] || 2000)
let runs = 0
function runOnce () {
runs++
https.get(url, (res) => {
res.setEncoding('utf8') // If this line is removed, the crash doesn't happen.
res.on('readable', () => {
// Race condition: The call to `res.read(100)` might throw
while (res.read(100) !== null) {}
})
res.on('end', () => {
if (runs >= maxRuns) {
console.log(`completed ${runs} runs without crash`)
} else {
runOnce()
}
})
})
}
console.log(`reproducing with ${url} for up to ${maxRuns} runs...`)
runOnce()
And here's the output:
reproducing with https://www.google.com for up to 2000 runs...
node:internal/streams/readable:1650
} else if (n < buf[idx].length) {
^
TypeError: Cannot read properties of undefined (reading 'length')
at fromList (node:internal/streams/readable:1650:27)
at Readable.read (node:internal/streams/readable:756:11)
at IncomingMessage.
Open Graph Description: Correct fromList() in decoded string mode to compare n against the current chunk length, not the buffer array length. This prevents over-consuming chunks, which can corrupt readable state and crash...
X Description: Correct fromList() in decoded string mode to compare n against the current chunk length, not the buffer array length. This prevents over-consuming chunks, which can corrupt readable state and crash...
Opengraph URL: https://github.com/nodejs/node/pull/61884
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:f672f7bb-e22d-bd54-f0e2-9917d09a334a |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DC00:163FF7:E2B0F:144522:6A4CC807 |
| html-safe-nonce | d27987edf7df9df2584b63abf561617263527dd494565428ce5a6618ec9f1c65 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzAwOjE2M0ZGNzpFMkIwRjoxNDQ1MjI6NkE0Q0M4MDciLCJ2aXNpdG9yX2lkIjoiNDc3ODA2ODgwOTgzMDE1NjI5NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d3dc911a4f3e119193e29915f9199a741fad6d7799e5e1f296e2b42ee2bc10b0 |
| hovercard-subject-tag | pull_request:3302382626 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/nodejs/node/pull/61884/files |
| twitter:image | https://avatars.githubusercontent.com/u/10602?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/10602?s=400&v=4 |
| og:image:alt | Correct fromList() in decoded string mode to compare n against the current chunk length, not the buffer array length. This prevents over-consuming chunks, which can corrupt readable state and crash... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3d11bb817438277de2a940854450e83a7d32b6aeb5014e9e6b00a6423900251c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d0da0eb92994395299ed4450bf67b0373005be36 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width