Title: os: getPriority() and setPriority() abort the process when passed -0 · Issue #67648 · nodejs/node · GitHub
Open Graph Title: os: getPriority() and setPriority() abort the process when passed -0 · Issue #67648 · nodejs/node
X Title: os: getPriority() and setPriority() abort the process when passed -0 · Issue #67648 · nodejs/node
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 negativ...
Open Graph 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 reproduc...
X 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 reproduc...
Opengraph URL: https://github.com/nodejs/node/issues/67648
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"os: getPriority() and setPriority() abort the process when passed -0","articleBody":"## Version \n`v24.8.0`\n\n## Platform\nMicrosoft Windows 11 Home 10.0.26200 x64\n\n- **Architecture:** x64\n- **Subsystem:** `os`\n- **Testing:** Reproduced and verified on Windows 11. Linux has not been tested.\n\n## What steps will reproduce the bug?\n\nThe issue occurs when negative zero (`-0`) is passed as a PID or priority argument to the Node.js `os` module.\n\nThe following examples reproduce the problem:\n\n```js\nconst os = require('node:os');\n\nos.getPriority(-0);\n```\n\n```js\nconst os = require('node:os');\n\nos.setPriority(-0);\n```\n\n```js\nconst os = require('node:os');\n\nos.setPriority(0, -0);\n```\n\nA realistic example is when a priority value is calculated dynamically:\n\n```js\nconst os = require('node:os');\n\nconst boostLevel = 0;\n\nos.setPriority(-boostLevel);\n```\n\nAlthough `boostLevel` is `0`, negating it produces JavaScript negative zero (`-0`).\n\n## How often does it reproduce? Is there a required condition?\n\nIt reproduces consistently whenever `-0` is passed as the PID or priority argument to the affected APIs.\n\nI tested all three examples on Windows 11 using Node.js `v24.8.0`. All three resulted in native assertion failures and process termination.\n\n## What is the expected behavior? Why is that expected?\n\nNegative zero is a valid JavaScript number and should be handled safely by the `os` module.\n\nSpecifically:\n\n1. `-0` passes the existing `validateInt32()` validation because `Number.isInteger(-0)` evaluates to `true`.\n2. Since JavaScript considers `-0` numerically equivalent to `0`, the API should handle it the same way as `0`.\n3. 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.\n4. Native assertions should never cause a process abort when an input has already passed JavaScript-level argument validation.\n\nThere is an existing precedent in the `fs` module, fixed in #65888.\n\n## What do you see instead?\n\nInstead of returning normally or throwing a catchable JavaScript exception, Node.js terminates the process with a native assertion failure.\n\n### 1. `os.getPriority(-0)`\n\n```text\nvoid __cdecl node::os::GetPriority(const FunctionCallbackInfo\u003cValue> &) at src\\node_os.cc:398\nAssertion failed: args[0]->IsInt32()\n\n----- Native stack trace -----\n1: 00007FF7A6A4B11A DSA_meth_get_flags+198106\n2: 00007FF7A69A9605 node::MultiIsolatePlatform::DisposeIsolate+36069\n3: 000002559FDCF64D\n```\n\n### 2. `os.setPriority(-0)` and `os.setPriority(0, -0)`\n\n```text\nvoid __cdecl node::os::SetPriority(const FunctionCallbackInfo\u003cValue> &) at src\\node_os.cc:376\nAssertion failed: args[1]->IsInt32()\n\n----- Native stack trace -----\n1: 00007FF7A6A4B11A DSA_meth_get_flags+198106\n2: 00007FF7A69A944E node::MultiIsolatePlatform::DisposeIsolate+35630\n3: 00000200D8ACF64D\n```\n\nBoth `setPriority()` examples produce the same assertion failure.\n\n## Additional information\n\n### Root cause\n\nThe issue appears to originate from a mismatch between JavaScript-level integer validation and V8's internal integer representation.\n\nThe existing `validateInt32()` validation accepts negative zero because:\n\n```js\nNumber.isInteger(-0) === true\n```\n\nHowever, V8's `Value::IsInt32()` returns `false` for negative zero.\n\nThis happens because V8 represents `-0` as a heap number rather than an ordinary signed 32-bit integer.\n\nConsequently, when the validated argument reaches the native implementation in `src/node_os.cc`, the following assertion fails:\n\n```cpp\nCHECK(args[0]->IsInt32());\n```\n\nFor `setPriority()`, the corresponding assertion is:\n\n```cpp\nCHECK(args[1]->IsInt32());\n```\n\nThe assertion failure causes Node.js to abort instead of handling the argument safely.\n\n### Related precedent\n\nThe 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`.\n\n\n### Proposed fix\n\nOne possible solution is to normalize validated integer arguments before passing them to the native binding.\n\nFor example, in `lib/os.js`, coerce the relevant arguments to signed 32-bit integers using `| 0` before invoking the native binding:\n\n```js\nconst normalizedPid = pid | 0;\nconst normalizedPriority = priority | 0;\n```\n\nThis converts `-0` to `0`, ensuring that V8 receives a value compatible with the native `IsInt32()` assertion.\n\nThe fix should also include a regression test:\n\n`test/parallel/test-os-negative-zero.js`\n\nThe test should cover:\n\n- `os.getPriority(-0)`\n- `os.setPriority(-0)`\n- `os.setPriority(0, -0)`\n\nThe tests should verify that negative zero is handled safely and does not cause a native process abort.\n\n\n### AI disclosure\n\nI 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.\n","author":{"url":"https://github.com/zelalem61","@type":"Person","name":"zelalem61"},"datePublished":"2026-11-20T11:32:48Z","url":"https://github.com/nodejs/node/issues/67648"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:05f97a6d-345a-135d-fd94-553b9213ab47 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D938:2C4BED:2FF4179:3CEBBAC:6B01C689 |
| html-safe-nonce | 3e79259836bd5c0c8379f7143f457c649c44f83edc8ae6204f5507f83e97c8b2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTM4OjJDNEJFRDoyRkY0MTc5OjNDRUJCQUM6NkIwMUM2ODkiLCJ2aXNpdG9yX2lkIjoiODQ5NzAyOTUzNzc0MDIxMTg0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d5ef0c4f0d8d457391f724e60b7db334ae8e116f3443ba7c50092ef44288393a |
| hovercard-subject-tag | issue:6510587815 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/nodejs/node/67648/issue_layout |
| twitter:image | https://opengraph.githubassets.com/233b76a92d5402ca56ac74cb51a41f73d03d3ac34ae7cc54b998cf6b2217828c/nodejs/node/issues/67648 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/233b76a92d5402ca56ac74cb51a41f73d03d3ac34ae7cc54b998cf6b2217828c/nodejs/node/issues/67648 |
| og:image:alt | 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 reproduc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zelalem61 |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width