Title: buffer: UTF-16LE indexOf can hang on unaligned Buffer views · Issue #65959 · nodejs/node · GitHub
Open Graph Title: buffer: UTF-16LE indexOf can hang on unaligned Buffer views · Issue #65959 · nodejs/node
X Title: buffer: UTF-16LE indexOf can hang on unaligned Buffer views · Issue #65959 · nodejs/node
Description: Version v27.0.0-pre (b805fb5158a) Platform Darwin 24.6.0 arm64 Subsystem buffer What steps will reproduce the bug? Buffer#indexOf() can hang when its receiver is an unaligned view. The child process timeout prevents the reproduction from...
Open Graph Description: Version v27.0.0-pre (b805fb5158a) Platform Darwin 24.6.0 arm64 Subsystem buffer What steps will reproduce the bug? Buffer#indexOf() can hang when its receiver is an unaligned view. The child proces...
X Description: Version v27.0.0-pre (b805fb5158a) Platform Darwin 24.6.0 arm64 Subsystem buffer What steps will reproduce the bug? Buffer#indexOf() can hang when its receiver is an unaligned view. The child proces...
Opengraph URL: https://github.com/nodejs/node/issues/65959
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"buffer: UTF-16LE indexOf can hang on unaligned Buffer views","articleBody":"### Version\n\nv27.0.0-pre (`b805fb5158a`)\n\n### Platform\n\n```text\nDarwin 24.6.0 arm64\n```\n\n### Subsystem\n\nbuffer\n\n### What steps will reproduce the bug?\n\n`Buffer#indexOf()` can hang when its receiver is an unaligned view. The child process timeout prevents the reproduction from hanging indefinitely.\n\n```js\n'use strict';\n\nconst { spawnSync } = require('node:child_process');\n\nfor (const prefixLength of [0, 1]) {\n const source = `\n const data = Buffer.from('abc', 'utf16le');\n const backing = Buffer.alloc(data.length + ${prefixLength});\n data.copy(backing, ${prefixLength});\n\n const view = backing.subarray(${prefixLength});\n console.log(view.indexOf('a', 0, 'utf16le'));\n `;\n\n const result = spawnSync(process.execPath, ['-e', source], {\n encoding: 'utf8',\n timeout: 2000,\n });\n\n console.log({\n prefixLength,\n status: result.status,\n error: result.error?.code,\n stdout: result.stdout.trim(),\n });\n}\n```\n\n### How often does it reproduce? Is there a required condition?\n\nIt's consistent when the receiver view starts at an odd byte offset. The aligned control returns normally.\n\n### What is the expected behavior? Why is that the expected behavior?\n\nBoth searches should terminate and return `0`.\nThe views contain the same bytes, and the UTF-16LE value begins at index 0 of each view. The result should not depend on the underlying memory address.\n\n### What do you see instead?\n\nThe aligned view returns `0`. The view starting at byte offset 1 does not complete before the timeout:\n\n```\n{ prefixLength: 0, status: 0, error: undefined, stdout: '0' }\n{ prefixLength: 1, status: null, error: 'ETIMEDOUT', stdout: '' }\n```\n\n### Additional information\n\n`Buffer#indexOf()` [passes the receiver data to the 16-bit search](https://github.com/nodejs/node/blob/b805fb5158a33f6dc0c213165edddc35045f4eb3/src/node_buffer.cc#L1119-L1124), while `nbytes` [aligns matched addresses down](https://github.com/nodejs/node/blob/b805fb5158a33f6dc0c213165edddc35045f4eb3/deps/nbytes/include/nbytes.h#L459-L465). For an odd-offset view, this can move before the start of the view and appears to cause the hang.\n\nThis is distinct from #26448, which concerns search-offset rounding, and remains reproducible after #65905, which affects UTF-16LE decoding rather than `Buffer#indexOf()`.\n\nCopying the view or using a `Buffer` needle avoids the hang. Both workarounds return `0` locally:\n```js\nBuffer.from(view).indexOf('a', 0, 'utf16le');\nview.indexOf(Buffer.from('a', 'utf16le'));\n```","author":{"url":"https://github.com/inoway46","@type":"Person","name":"inoway46"},"datePublished":"2026-09-10T11:52:06Z","url":"https://github.com/nodejs/node/issues/65959"}
| 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:dd47e6fb-4e64-a679-fc79-e0d20efb2a08 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DC0A:257A3D:7948E1:A1751D:6AED2628 |
| html-safe-nonce | ca939e40e33c7160c0232b668da6cd681420405603661c11a46752c890c2725d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzBBOjI1N0EzRDo3OTQ4RTE6QTE3NTFEOjZBRUQyNjI4IiwidmlzaXRvcl9pZCI6IjcxNjgyNzk4NjczOTk0MTUzMzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 20b7a13b157efb9830751104bc3ee31bb4d4a7e29c27a747f9298498f1fdd187 |
| hovercard-subject-tag | issue:5411811927 |
| 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/65959/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ee09a9926669128d8c2af20028cf805a965f2d19c587d9cf86e0d549b83daeba/nodejs/node/issues/65959 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ee09a9926669128d8c2af20028cf805a965f2d19c587d9cf86e0d549b83daeba/nodejs/node/issues/65959 |
| og:image:alt | Version v27.0.0-pre (b805fb5158a) Platform Darwin 24.6.0 arm64 Subsystem buffer What steps will reproduce the bug? Buffer#indexOf() can hang when its receiver is an unaligned view. The child proces... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | inoway46 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9d95365dda0576efe9b71f45807595e396bd0ca9286fba5367a05048e6ddf8f2 |
| 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 | 98b41fa4b5635ceb45a4c54320fced73817ff290 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width