Title: Utf8Stream writes duplicate bytes when a short write splits a multi-byte character · Issue #67679 · nodejs/node · GitHub
Open Graph Title: Utf8Stream writes duplicate bytes when a short write splits a multi-byte character · Issue #67679 · nodejs/node
X Title: Utf8Stream writes duplicate bytes when a short write splits a multi-byte character · Issue #67679 · nodejs/node
Description: Version v28.0.0-pre (main), v26.13.1, v24.22.3 Platform Darwin 24.6.0 arm64 Subsystem fs What steps will reproduce the bug? When fs.write() commits only partial of a string and the cut lands inside a multi byte UTF-8 character, fs.Utf8St...
Open Graph Description: Version v28.0.0-pre (main), v26.13.1, v24.22.3 Platform Darwin 24.6.0 arm64 Subsystem fs What steps will reproduce the bug? When fs.write() commits only partial of a string and the cut lands inside...
X Description: Version v28.0.0-pre (main), v26.13.1, v24.22.3 Platform Darwin 24.6.0 arm64 Subsystem fs What steps will reproduce the bug? When fs.write() commits only partial of a string and the cut lands inside...
Opengraph URL: https://github.com/nodejs/node/issues/67679
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Utf8Stream writes duplicate bytes when a short write splits a multi-byte character","articleBody":"### Version\n\nv28.0.0-pre (main), v26.13.1, v24.22.3\n\n### Platform\n\n```text\nDarwin 24.6.0 arm64\n```\n\n### Subsystem\n\nfs\n\n### What steps will reproduce the bug?\n\nWhen `fs.write()` commits only partial of a string and the cut lands inside a multi byte UTF-8 character, `fs.Utf8Stream` leaves the already written lead bytes on the **_fd_** and then **_writes the whole character again_**.\n\nSee repro below forces one short write through the `fs` option. The short write itself is real: 4 of the 9 bytes of `'abc中def'` reach the fd, which cuts `中` (`e4 b8 ad`) after its first byte.\n\n``` js\n'use strict';\nconst fs = require('node:fs');\nconst os = require('node:os');\nconst path = require('node:path');\n\nconst file = path.join(os.tmpdir(), `utf8stream-${process.pid}.txt`);\nconst fd = fs.openSync(file, 'w');\n\nlet shortWriteDone = false;\nconst stream = new fs.Utf8Stream({\n fd,\n fs: {\n // Simulate a short write: the first call commits only 4 of 9 bytes,\n // which cuts '中' (e4 b8 ad) after its first byte.\n write(fd, data, ...rest) {\n if (shortWriteDone) return fs.write(fd, data, ...rest);\n shortWriteDone = true;\n fs.write(fd, Buffer.from(data).subarray(0, 4), rest.at(-1));\n },\n },\n});\n\nstream.on('ready', () => {\n stream.write('abc中def');\n stream.end();\n});\n\nstream.on('close', () => {\n const actual = fs.readFileSync(file);\n fs.unlinkSync(file);\n console.log('expected:', Buffer.from('abc中def').toString('hex'));\n console.log('actual: ', actual.toString('hex'), JSON.stringify(actual.toString()));\n});\n```\n\n### How often does it reproduce? Is there a required condition?\n\nAlways\n\n### What is the expected behavior? Why is that the expected behavior?\n\n``` text\nexpected: 616263e4b8ad646566\n```\n\n### What do you see instead?\n\n``` text\nactual: 616263e4e4b8ad646566 \"abc�中def\"\n```\n\n### Additional information\n\n_No response_","author":{"url":"https://github.com/jakecastelli","@type":"Person","name":"jakecastelli"},"datePublished":"2026-11-21T13:58:46Z","url":"https://github.com/nodejs/node/issues/67679"}
| 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:6df9d10f-fb88-e05a-45c6-372f4de38fc2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9D92:3DEF55:403693:53ECF8:6B06199C |
| html-safe-nonce | e3651f1746257ff0c2e07b30ba2cbbb37cc7d503b1579aba83031e7d8d267736 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RDkyOjNERUY1NTo0MDM2OTM6NTNFQ0Y4OjZCMDYxOTlDIiwidmlzaXRvcl9pZCI6IjM1NzgyNTA2NTkzODk4MzMyNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ebc503359b5189eb04d4e2ee1907408bea8601e73eb82fe461f3a8005f777f7f |
| hovercard-subject-tag | issue:6529742932 |
| 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/67679/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c5127f0ac7db5de5d5d038eca4e12e86ba9cc78fe8ca4d4be3ad2d60bc8403f9/nodejs/node/issues/67679 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c5127f0ac7db5de5d5d038eca4e12e86ba9cc78fe8ca4d4be3ad2d60bc8403f9/nodejs/node/issues/67679 |
| og:image:alt | Version v28.0.0-pre (main), v26.13.1, v24.22.3 Platform Darwin 24.6.0 arm64 Subsystem fs What steps will reproduce the bug? When fs.write() commits only partial of a string and the cut lands inside... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jakecastelli |
| hostname | github.com |
| expected-hostname | github.com |
| None | 97d4714e567728e1f85f88b0cf68c89f0f8a3dc41e8869af7aeb8195ad990374 |
| 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 | 866f202ebf7ac5aff8f633417d9fd8a53818a977 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width