fs: fix crash on negative zero file descriptor · nodejs/node@99a78b0 · GitHub
Skip to content

Commit 99a78b0

Browse files
christianaurichzmaduh95
authored andcommitted
fs: fix crash on negative zero file descriptor
`isInt32()` accepts -0 because `-0 === (-0 | 0)`, but V8 does not represent -0 as an Int32 value, so `Value::IsInt32()` rejects it. The utf8 fast paths of `readFileSync()` and `writeFileSync()` hand the value straight to the binding, which then took it for a path and aborted on the null check. Coerce -0 to 0 before the call, matching `getValidatedFd()` and the rest of fs, where -0 is a valid way to name file descriptor 0. Signed-off-by: Christian Aurich <christian.aurichzm@gmail.com> PR-URL: #65888 Fixes: #65886 Reviewed-By: Xuguang Mei <meixuguang@gmail.com>
1 parent b896580 commit 99a78b0

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎lib/fs.js‎

Lines changed: 10 additions & 2 deletions

‎test/parallel/test-fs-negative-zero.js‎

Lines changed: 15 additions & 0 deletions

0 commit comments

Comments
 (0)