-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs.writeFile[Sync] may corrupt files upon partial write #1058
Comments
Good catch, this looks like a serious issue. |
Continues in #1063 |
rvagg
added a commit
that referenced
this issue
Mar 31, 2015
Notable changes: * fs: corruption can be caused by fs.writeFileSync() and append-mode fs.writeFile() and fs.writeFileSync() under certain circumstances, reported in #1058, fixed in #1063 (Olov Lassus). * iojs: an "internal modules" API has been introduced to allow core code to share JavaScript modules internally only without having to expose them as a public API, this feature is for core-only #848 (Vladimir Kurchatkin). * timers: two minor problems with timers have been fixed: - Timer#close() is now properly idempotent #1288 (Petka Antonov). - setTimeout() will only run the callback once now after an unref() during the callback #1231 (Roman Reiss). * Windows: a "delay-load hook" has been added for compiled add-ons on Windows that should alleviate some of the problems that Windows users may be experiencing with add-ons in io.js #1251 (Bert Belder). * V8: minor bug-fix upgrade for V8 to 4.1.0.27. * npm: upgrade npm to 2.7.4. See npm CHANGELOG.md for details.
ilgrosso
pushed a commit
to OpenRock/OpenAM
that referenced
this issue
Nov 3, 2015
The current version of Node.js and/or npm seems to be sporadically corrupting files (possibly related to nodejs/node#1058). v4.2.1 is the latest LTS version of Node.js.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Two semi-related issues:
writeFileSync
bumpsposition
incorrectly, causing it to drift in iteration three and onwards. It seems thatwritten
is though to be the amount just written but it is in fact the accumulated amount. This bug is not available in the asyncwriteFile
.writeFile
orwriteFileSync
iterates multiple times, unless running on Linux.position
starts out asnull
so first write is OK, but thenposition
will refer to a location inside an existing file, corrupting that data. Linux ignores position for append mode files so it doesn't happen there.See https://github.com/iojs/io.js/blob/78581c8d902f2ed32712b342091d89016030e4ba/lib/fs.js#L1151-L1155 (also
writeFile
andwriteAll
).The text was updated successfully, but these errors were encountered: