Title: Buffer.prototype.indexOf returns a negative (int32-wrapped) position for matches beyond 2 GiB · Issue #66294 · nodejs/node · GitHub
Open Graph Title: Buffer.prototype.indexOf returns a negative (int32-wrapped) position for matches beyond 2 GiB · Issue #66294 · nodejs/node
X Title: Buffer.prototype.indexOf returns a negative (int32-wrapped) position for matches beyond 2 GiB · Issue #66294 · nodejs/node
Description: Version v26.10.0 and v24.21.0 (official win-x64 builds); v22.22.2 on Linux x64; first seen on v24.16.0 and on Node 24.20.0 as embedded in Electron 43.6.0 Platform Windows 10 22H2 x64 (build 19045.6466), 64 GB RAM; also Linux x86_64 Subsy...
Open Graph Description: Version v26.10.0 and v24.21.0 (official win-x64 builds); v22.22.2 on Linux x64; first seen on v24.16.0 and on Node 24.20.0 as embedded in Electron 43.6.0 Platform Windows 10 22H2 x64 (build 19045.6...
X Description: Version v26.10.0 and v24.21.0 (official win-x64 builds); v22.22.2 on Linux x64; first seen on v24.16.0 and on Node 24.20.0 as embedded in Electron 43.6.0 Platform Windows 10 22H2 x64 (build 19045.6...
Opengraph URL: https://github.com/nodejs/node/issues/66294
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Buffer.prototype.indexOf returns a negative (int32-wrapped) position for matches beyond 2 GiB","articleBody":"### Version\n\nv26.10.0 and v24.21.0 (official win-x64 builds); v22.22.2 on Linux x64; first seen on v24.16.0 and on Node 24.20.0 as embedded in Electron 43.6.0\n\n### Platform\n\n```text\nWindows 10 22H2 x64 (build 19045.6466), 64 GB RAM; also Linux x86_64\n```\n\n### Subsystem\n\nbuffer\n\n### What steps will reproduce the bug?\n\n```js\nconst big = Buffer.alloc(2 ** 31 + 4096, 97);\nconst hit = 2 ** 31 + 100;\nbig[hit] = 10;\nconsole.log(big.indexOf(10, 2 ** 31 + 50)); // number needle\nconsole.log(big.indexOf(Buffer.from([10]), 2 ** 31 + 50)); // Buffer needle\nconsole.log(big.indexOf('\\n', 2 ** 31 + 50)); // string needle\n```\n\nFull script with a below-2 GiB control: `indexof_2gib.js` in https://gist.github.com/BlackWhiteYellow/f44e367254db24fbe20d7fe10002ab1f (needs ~4.5 GB of free RAM).\n\n### How often does it reproduce? Is there a required condition?\n\nAlways, when the match position is ≥ 2^31, on every version and platform listed above. Matches below 2^31 in a buffer just under 2 GiB are returned correctly.\n\n### What is the expected behavior? Why is that the expected behavior?\n\n`2147483748`, the byte offset of the match. `Buffer.alloc` accepts lengths above 2^31 on 64-bit, so `indexOf` should return offsets in that range, as documented for the method.\n\n### What do you see instead?\n\n`-2147483548` for all three needle types, which equals `2147483748 − 2^32` (the offset truncated to int32).\n\n### Additional information\n\nConsumers that treat only `-1` as \"not found\" then move their cursor backwards; in the Claude Code VS Code extension this turns into an endless re-parse loop and an out-of-memory crash of the editor's extension host (downstream report linked in a comment below). nodejs/node#62711 (commit 49198d2, the fix for #62873) changed how the `end` parameter of indexOf/lastIndexOf is handled; it does not change how the found position is returned.","author":{"url":"https://github.com/BlackWhiteYellow","@type":"Person","name":"BlackWhiteYellow"},"datePublished":"2026-09-25T18:12:53Z","url":"https://github.com/nodejs/node/issues/66294"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| 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:5aa242f9-1901-7a77-8c4b-91a8048c33a8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AD7E:257BEE:9F53E1:D371F9:6AED3162 |
| html-safe-nonce | ad45cea053f19765d155eb854509af1b11445a0ae3182252b14ab01f9866f27c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRDdFOjI1N0JFRTo5RjUzRTE6RDM3MUY5OjZBRUQzMTYyIiwidmlzaXRvcl9pZCI6IjE2MDczMTQ1NDIyMTMwMTc5NTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 73eed47af3b5ffbb6322d1bd0a2f6988841143ddef129b52640527ab35c5112f |
| hovercard-subject-tag | issue:5586695573 |
| 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/66294/issue_layout |
| twitter:image | https://opengraph.githubassets.com/56365971b2125bdaa60c6f1c413c378d382399e51bb1d493cf77a3c703366d0d/nodejs/node/issues/66294 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/56365971b2125bdaa60c6f1c413c378d382399e51bb1d493cf77a3c703366d0d/nodejs/node/issues/66294 |
| og:image:alt | Version v26.10.0 and v24.21.0 (official win-x64 builds); v22.22.2 on Linux x64; first seen on v24.16.0 and on Node 24.20.0 as embedded in Electron 43.6.0 Platform Windows 10 22H2 x64 (build 19045.6... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | BlackWhiteYellow |
| hostname | github.com |
| expected-hostname | github.com |
| None | e51d0b7b5ab34b1688c05b54c3ed17b8658b2fa9bca973a9c740683ccb12cf4a |
| 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 | 59ebb7b901cc154ecc179a44f266fcf69f343b30 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width