Title: TextDecoder: ERR_ENCODING_INVALID_ENCODED_DATA on very long array buffer · Issue #47645 · nodejs/node · GitHub
Open Graph Title: TextDecoder: ERR_ENCODING_INVALID_ENCODED_DATA on very long array buffer · Issue #47645 · nodejs/node
X Title: TextDecoder: ERR_ENCODING_INVALID_ENCODED_DATA on very long array buffer · Issue #47645 · nodejs/node
Description: Version v18.14.1 Platform Linux 5.19.0-38-generic #39~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 21:16:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux Subsystem No response What steps will reproduce the bug? When I try to decode a long utf-16...
Open Graph Description: Version v18.14.1 Platform Linux 5.19.0-38-generic #39~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 21:16:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux Subsystem No response What steps will reproduce the...
X Description: Version v18.14.1 Platform Linux 5.19.0-38-generic #39~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 21:16:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux Subsystem No response What steps will reproduce the...
Opengraph URL: https://github.com/nodejs/node/issues/47645
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TextDecoder: ERR_ENCODING_INVALID_ENCODED_DATA on very long array buffer","articleBody":"### Version\r\n\r\nv18.14.1\r\n\r\n### Platform\r\n\r\nLinux 5.19.0-38-generic #39~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 21:16:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux\r\n\r\n### Subsystem\r\n\r\n_No response_\r\n\r\n### What steps will reproduce the bug?\r\n\r\nWhen I try to decode a long utf-16le encoded buffer, ERR_ENCODING_INVALID_ENCODED_DATA is thrown instead of ERR_STRING_TOO_LONG.\r\n```js\r\nnew TextDecoder(\"utf-16le\").decode(new Uint16Array(2**27).fill(48))\r\n// Uncaught TypeError: The encoded data was not valid for encoding utf-16le\r\n// at TextDecoder.decode (node:internal/encoding:448:14) {\r\n// code: 'ERR_ENCODING_INVALID_ENCODED_DATA'\r\n// }\r\n```\r\nThe default encoding version seems to work correctly, and throws an appropriate error\r\n```js\r\nnew TextDecoder().decode(new Uint8Array(2**29).fill(48))\r\n// Uncaught Error: Cannot create a string longer than 0x1fffffe8 characters\r\n// at TextDecoder.decode (node:internal/encoding:433:16) {\r\n// code: 'ERR_STRING_TOO_LONG'\r\n// }\r\n```\r\nAnother thing that I realized is that `TextDecoder()` seems to be capable of consuming an array buffer twice as long as `TextDecoder(\"utf-16le\")` without throwing error, and produce a string that's 4 times as long.\r\n\r\n### How often does it reproduce? Is there a required condition?\r\n\r\nConfirmed this bug in both normal file execution and node.js repl\r\n\r\n### What is the expected behavior? Why is that the expected behavior?\r\n\r\n`new TextDecoder(\"utf-16le\")` should be able to create a string up to 0x1fffffe8 characters.\r\nIt should throw ERR_STRING_TOO_LONG when this length is exceeded.\r\n\r\n### What do you see instead?\r\n\r\nERR_ENCODING_INVALID_ENCODED_DATA is thrown when the input Uint16Array length is 2**27\r\n```\r\nUncaught TypeError: The encoded data was not valid for encoding utf-16le\r\n at TextDecoder.decode (node:internal/encoding:448:14) {\r\n code: 'ERR_ENCODING_INVALID_ENCODED_DATA'\r\n}\r\n```\r\n\r\n### Additional information\r\n\r\n_No response_","author":{"url":"https://github.com/martian17","@type":"Person","name":"martian17"},"datePublished":"2023-04-20T16:10:17Z","url":"https://github.com/nodejs/node/issues/47645"}
| 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:394e26ba-c845-6a06-1051-df348c18567b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D36E:27868A:6BB6BC:9221A0:6AED27D2 |
| html-safe-nonce | 37e59a25a906851227554b13555f83499f944a749430682a295a035e197751f7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzZFOjI3ODY4QTo2QkI2QkM6OTIyMUEwOjZBRUQyN0QyIiwidmlzaXRvcl9pZCI6Ijc4NzA4NjQ1NzIwMjc4NDA0NjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 230a12bf478d267c0c0b0a38565f8274a2b017596e302dfe0e338af4b109459a |
| hovercard-subject-tag | issue:1677024545 |
| 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/47645/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8870c0ebd1a2e20a884fdf8d8351e42f4b665d614c252ca8cf5cd01f5a03c088/nodejs/node/issues/47645 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8870c0ebd1a2e20a884fdf8d8351e42f4b665d614c252ca8cf5cd01f5a03c088/nodejs/node/issues/47645 |
| og:image:alt | Version v18.14.1 Platform Linux 5.19.0-38-generic #39~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 21:16:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux Subsystem No response What steps will reproduce the... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | martian17 |
| 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