Repository navigation
Description
Version
v24.8.0
Platform
Microsoft Windows 11 Home 10.0.26200 x64
- Architecture: x64
- Subsystem:
os - Testing: Reproduced and verified on Windows 11. Linux has not been tested.
What steps will reproduce the bug?
The issue occurs when negative zero (-0) is passed as a PID or priority argument to the Node.js os module.
The following examples reproduce the problem:
const os = require('node:os');
os.getPriority(-0);const os = require('node:os');
os.setPriority(-0);const os = require('node:os');
os.setPriority(0, -0);A realistic example is when a priority value is calculated dynamically:
const os = require('node:os');
const boostLevel = 0;
os.setPriority(-boostLevel);Although boostLevel is 0, negating it produces JavaScript negative zero (-0).
How often does it reproduce? Is there a required condition?
It reproduces consistently whenever -0 is passed as the PID or priority argument to the affected APIs.
I tested all three examples on Windows 11 using Node.js v24.8.0. All three resulted in native assertion failures and process termination.
What is the expected behavior? Why is that expected?
Negative zero is a valid JavaScript number and should be handled safely by the os module.
Specifically:
-0passes the existingvalidateInt32()validation becauseNumber.isInteger(-0)evaluates totrue.- Since JavaScript considers
-0numerically equivalent to0, the API should handle it the same way as0. - Alternatively, if negative zero is not supported for a particular argument, the API should throw a normal, catchable JavaScript exception rather than terminating the entire Node.js process.
- Native assertions should never cause a process abort when an input has already passed JavaScript-level argument validation.
There is an existing precedent in the fs module, fixed in #65888.
What do you see instead?
Instead of returning normally or throwing a catchable JavaScript exception, Node.js terminates the process with a native assertion failure.
1. os.getPriority(-0)
void __cdecl node::os::GetPriority(const FunctionCallbackInfo<Value> &) at src\node_os.cc:398
Assertion failed: args[0]->IsInt32()
----- Native stack trace -----
1: 00007FF7A6A4B11A DSA_meth_get_flags+198106
2: 00007FF7A69A9605 node::MultiIsolatePlatform::DisposeIsolate+36069
3: 000002559FDCF64D
2. os.setPriority(-0) and os.setPriority(0, -0)
void __cdecl node::os::SetPriority(const FunctionCallbackInfo<Value> &) at src\node_os.cc:376
Assertion failed: args[1]->IsInt32()
----- Native stack trace -----
1: 00007FF7A6A4B11A DSA_meth_get_flags+198106
2: 00007FF7A69A944E node::MultiIsolatePlatform::DisposeIsolate+35630
3: 00000200D8ACF64D
Both setPriority() examples produce the same assertion failure.
Additional information
Root cause
The issue appears to originate from a mismatch between JavaScript-level integer validation and V8's internal integer representation.
The existing validateInt32() validation accepts negative zero because:
Number.isInteger(-0) === trueHowever, V8's Value::IsInt32() returns false for negative zero.
This happens because V8 represents -0 as a heap number rather than an ordinary signed 32-bit integer.
Consequently, when the validated argument reaches the native implementation in src/node_os.cc, the following assertion fails:
CHECK(args[0]->IsInt32());For setPriority(), the corresponding assertion is:
CHECK(args[1]->IsInt32());The assertion failure causes Node.js to abort instead of handling the argument safely.
Related precedent
The same kind of bug was fixed in fs in #65888, which coerces negative zero before it reaches the binding. There are also existing test-*-negative-zero.js tests for fs, crypto, net, zlib and dns.
Proposed fix
One possible solution is to normalize validated integer arguments before passing them to the native binding.
For example, in lib/os.js, coerce the relevant arguments to signed 32-bit integers using | 0 before invoking the native binding:
const normalizedPid = pid | 0;
const normalizedPriority = priority | 0;This converts -0 to 0, ensuring that V8 receives a value compatible with the native IsInt32() assertion.
The fix should also include a regression test:
test/parallel/test-os-negative-zero.js
The test should cover:
os.getPriority(-0)os.setPriority(-0)os.setPriority(0, -0)
The tests should verify that negative zero is handled safely and does not cause a native process abort.
AI disclosure
I used AI assistance to help understand the Node.js codebase, investigate the potential root cause, and identify related negative-zero handling issues in other modules. I then independently reproduced the issue on Windows using Node.js v24.8.0 and verified that all three examples trigger native assertion failures.
Activity