Skip to content

Commit 0aa8cd0

Browse files
authored
fix(release): avoid Node UTF-8 pipe read overflow (#21222)
> ### Branch strategy > > - Active development targets `main`. ### What this PR does Before this PR: Pre Release could crash with exit 139 while Node 24.21.0 read the piped release list. After this PR: Read stdin as a Buffer before UTF-8 decoding, with regression coverage for short pipe reads followed by a large write and duplicate-version rejection. N/A — no repository issue ### Why we need it and why it was done in this way The following tradeoffs were made: A one-line workaround for the affected Node UTF-8 fast path; unchanged release validation rules The following alternatives were considered: Waiting for the upstream Node fix or changing the repository-wide Node version Links to places where the discussion took place: [Failed CI job](https://github.com/CherryHQ/cherry-studio/actions/runs/36725980695/job/109939082205), [Node defect](nodejs/node#66341) ### Breaking changes None ### Special notes for your reviewer Validation: `pnpm lint`, 83 tests across `release-workflow.test.ts` and `release-baseline.test.ts`, and the real GitHub release-list pipeline passed on macOS; the original Linux crash was not reproduced locally and the remote release workflow has not been rerun. ### Checklist This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR. Approvers are expected to review this list. - [x] Branch: This PR targets `main` - [x] PR: The PR description is expressive enough and will help future contributors - [x] Code: [Write code that humans can understand](https://en.wikiquote.org/wiki/Martin_Fowler#code-for-humans) and [Keep it simple](https://en.wikipedia.org/wiki/KISS_principle) - [ ] Refactor: You have [left the code cleaner than you found it (Boy Scout Rule)](https://learning.oreilly.com/library/view/97-things-every/9780596809515/ch08.html) - [x] Upgrade: Impact of this change on upgrade flows was considered and addressed if required - [ ] Documentation: A [user-guide update](https://docs.cherry-ai.com) was considered and is present (link) or not required. Check this only when the PR introduces or changes a user-facing feature or behavior. - [x] Self-review: I have reviewed my own code (e.g., via [`/gh-pr-review`](/.claude/skills/gh-pr-review/SKILL.md), `gh pr diff`, or GitHub UI) before requesting review from others ### Release note ```release-note NONE ``` Signed-off-by: suyao <[email protected]>
1 parent cff21f7 commit 0aa8cd0

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎scripts/__tests__/release-workflow.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,43 @@ describe('release preparation state', () => {
679679
expect(result.status).toBe(0)
680680
expect(result.stderr).toBe('')
681681
})
682+
683+
it.each([
684+
{ tag: 'v1.2.0', status: 0, stderr: '' },
685+
{ tag: 'v1.1.0', status: 1, stderr: 'Release v1.1.0 already exists' }
686+
])('validates $tag after short pipe reads followed by a large write', ({ tag, status, stderr }) => {
687+
const validatorPath = path.resolve(import.meta.dirname, '../release/validate-release-state.js')
688+
const result = spawnSync(
689+
process.execPath,
690+
[
691+
'-e',
692+
`
693+
const { spawn } = require('node:child_process')
694+
const child = spawn(process.execPath, [process.argv[1], 'prepare'], {
695+
stdio: ['pipe', 'inherit', 'inherit']
696+
})
697+
child.on('exit', (code) => { process.exitCode = code ?? 1 })
698+
child.stdin.on('error', () => { process.exitCode = 1 })
699+
let writes = 0
700+
const timer = setInterval(() => {
701+
child.stdin.write(' '.repeat(4000))
702+
if (++writes === 24) {
703+
clearInterval(timer)
704+
child.stdin.end(' '.repeat(400000) + JSON.stringify([[{ tag_name: 'v1.1.0' }]]))
705+
}
706+
}, 5)
707+
`,
708+
validatorPath
709+
],
710+
{ encoding: 'utf8', env: { ...process.env, TAG: tag }, timeout: 5000 }
711+
)
712+
713+
expect(result.error).toBeUndefined()
714+
expect(result.signal).toBeNull()
715+
expect(result.status).toBe(status)
716+
if (stderr) expect(result.stderr).toContain(stderr)
717+
else expect(result.stderr).toBe('')
718+
})
682719
})
683720

684721
describe('release publication state', () => {

‎scripts/release/validate-release-state.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ function main() {
110110

111111
if (phase === 'prepare') {
112112
validatePreparationState({
113-
releasePages: parseOptionalJson(fs.readFileSync(0, 'utf8'), 'release list'),
113+
// Avoid Node 24.21.0's UTF-8 pipe-read overflow: https://github.com/nodejs/node/issues/66341.
114+
releasePages: parseOptionalJson(fs.readFileSync(0).toString('utf8'), 'release list'),
114115
tag
115116
})
116117
return

0 commit comments

Comments
 (0)