Skip to content

fs.writeFile[Sync] may corrupt files upon partial write #1058

Closed
@olov

Description

@olov

Two semi-related issues:

  1. writeFileSync bumps position incorrectly, causing it to drift in iteration three and onwards. It seems that written is though to be the amount just written but it is in fact the accumulated amount. This bug is not available in the async writeFile.
  2. Append mode files will get corrupted in the middle if writeFile or writeFileSync iterates multiple times, unless running on Linux. position starts out as null so first write is OK, but then position 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 and writeAll).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions