Skip to content

Commit f66d55f

Browse files
DeJeuneMidAutumnMoon
authored andcommitted
fix(release): avoid Node UTF-8 pipe read overflow (CherryHQ#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]> (cherry picked from commit 0aa8cd0)
1 parent 141a683 commit f66d55f

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
@@ -670,6 +670,43 @@ describe('release preparation state', () => {
670670
expect(result.status).toBe(0)
671671
expect(result.stderr).toBe('')
672672
})
673+
674+
it.each([
675+
{ tag: 'v1.2.0', status: 0, stderr: '' },
676+
{ tag: 'v1.1.0', status: 1, stderr: 'Release v1.1.0 already exists' }
677+
])('validates $tag after short pipe reads followed by a large write', ({ tag, status, stderr }) => {
678+
const validatorPath = path.resolve(import.meta.dirname, '../release/validate-release-state.js')
679+
const result = spawnSync(
680+
process.execPath,
681+
[
682+
'-e',
683+
`
684+
const { spawn } = require('node:child_process')
685+
const child = spawn(process.execPath, [process.argv[1], 'prepare'], {
686+
stdio: ['pipe', 'inherit', 'inherit']
687+
})
688+
child.on('exit', (code) => { process.exitCode = code ?? 1 })
689+
child.stdin.on('error', () => { process.exitCode = 1 })
690+
let writes = 0
691+
const timer = setInterval(() => {
692+
child.stdin.write(' '.repeat(4000))
693+
if (++writes === 24) {
694+
clearInterval(timer)
695+
child.stdin.end(' '.repeat(400000) + JSON.stringify([[{ tag_name: 'v1.1.0' }]]))
696+
}
697+
}, 5)
698+
`,
699+
validatorPath
700+
],
701+
{ encoding: 'utf8', env: { ...process.env, TAG: tag }, timeout: 5000 }
702+
)
703+
704+
expect(result.error).toBeUndefined()
705+
expect(result.signal).toBeNull()
706+
expect(result.status).toBe(status)
707+
if (stderr) expect(result.stderr).toContain(stderr)
708+
else expect(result.stderr).toBe('')
709+
})
673710
})
674711

675712
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)