jprichardson / jprichardson/node-fs-extra

Problems when dealing with invalidly-encoded filenames

Open
#575 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug platform-linux
Dominant language
JavaScript
Stars
9.6k
Forks
788
Avg merge
2d 11h
Merged PRs (30d)
3

Description

  • Operating System: Debian 9
  • Node.js version: 8.9.3
  • fs-extra version: 5.0.0

Hi there. I ran into some cases where remove() was unable to remove a directory due to filename encoding issues. I believe there are similar issues using empty, copy, and move operations (and their sync counterparts - basically anything that relies on fs.readdir / fs.readdirSync).

My issue arose when trying to fs.remove() some directories that were created from an unzip operation. During removes / rimraf's tree walk, some of the returned directories seemed not to exist (although they did), causing the final unlink operation to fail (since it wasn't actually successfully emptied).

It seems that, in general, names on a file system are just byte sequences, which are not guaranteed to represent fully valid strings. This causes the bytes-> string -> bytes operation, that happens when listing and then operating on items in a directory using Node, to not always produce the same file name that it read.

This encoding problem has been a known Node issue for a while, which is why an option was added to return Buffers from fs.readdir. My suggestion is to update the affected methods to use this Buffer option. I'm happy to work on a PR, but I wanted to at least get some feedback and discuss the issue before diving in.

Here are a couple Node issues relating to the file name encoding problem:

https://github.com/nodejs/node-v0.x-archive/issues/2387
https://github.com/nodejs/node/pull/5616

Thanks!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Trace remove, empty, copy, and move, including their sync counterparts, at the points that rely on fs.readdir or fs.readdirSync. Review Node's Buffer filename option first, then verify that operations handle invalidly encoded filenames without leaving directories incompletely emptied.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.