question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Line breaks in filenames cause infinite loops in mkdirs & mkdirsSync

See original GitHub issue
  • Operating System: Windows 10 Enterprise 2016
  • Node.js version: 6.10.2
  • fs-extra version: 4.0.3

It would be nice to have error handling for line breaks in the mkdirs and mkdirsSync methods.

Correct names:

> require('fs-extra').mkdirs('dir_correct');
Promise { <pending> }

> require('fs-extra').mkdirs('dir_correct', (a) => console.log('callback', a));
undefined
> callback null

> require('fs-extra').mkdirsSync('dir_correct');
null

Directories with \n in paths are not created. It’s okay, but here we get an infinite loop (at least in mkdirsSync), which is unacceptable in my opinion. In mkdirs with callback, the callback is not called.

> require('fs-extra').mkdirs('dir_incorrect\n');
Promise { <pending> }

> require('fs-extra').mkdirs('dir_incorrect\n', (a) => console.log('callback', a));
undefined

> require('fs-extra').mkdirsSync('dir_incorrect\n');
RangeError: Maximum call stack size exceeded
    at Object.fs.mkdirSync (fs.js:923:18)
    at mkdirsSync (C:\projects\test1\node_modules\fs-extra\lib\mkdirs\mkdirs-sync.js:31:9)
    at mkdirsSync (C:\projects\test1\node_modules\fs-extra\lib\mkdirs\mkdirs-sync.js:37:16)
    at mkdirsSync (C:\projects\test1\node_modules\fs-extra\lib\mkdirs\mkdirs-sync.js:38:9)
    at mkdirsSync (C:\projects\test1\node_modules\fs-extra\lib\mkdirs\mkdirs-sync.js:38:9)
    at mkdirsSync (C:\projects\test1\node_modules\fs-extra\lib\mkdirs\mkdirs-sync.js:38:9)
    at mkdirsSync (C:\projects\test1\node_modules\fs-extra\lib\mkdirs\mkdirs-sync.js:38:9)
    at mkdirsSync (C:\projects\test1\node_modules\fs-extra\lib\mkdirs\mkdirs-sync.js:38:9)
    at mkdirsSync (C:\projects\test1\node_modules\fs-extra\lib\mkdirs\mkdirs-sync.js:38:9)
    at mkdirsSync (C:\projects\test1\node_modules\fs-extra\lib\mkdirs\mkdirs-sync.js:38:9)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
RyanZimcommented, Feb 20, 2018

No wonder it crashes. ENOENT is also the error code we get when the parent doesn’t exist, so we respond by trying to create the parent. That causes an infinite loop.

Not sure what’s the best way to solve this, but we need to do something.

0reactions
RyanZimcommented, Oct 20, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Incrementing file name goes on infinite loop logic error C# ...
The thing is, I've tried to put break but what happens is that after it increments for the first time, an error appears...
Read more >
fs-extra/CHANGELOG.md - UNPKG
108, - `mkdirs()/mkdirsSync()` check for invalid win32 path chars. ... "In Windows invalid directory name causes infinite loop in ensureDir(). [bug]".
Read more >
Utils.cpp - Android Code Search
status_t WaitForFile(const char* filename, std::chrono::nanoseconds timeout) { ... bool MkdirsSync(const std::string& path, mode_t mode) {. if (path[0] !=
Read more >
reading filenames with newlines - bash - Unix Stack Exchange
I'd be seeing the NULLs? But No, the while loop exits after zero times around (in both cases) I assume because the read...
Read more >
Viewing online file analysis results for 'x.exe'
Persistence: Spawns a lot of processes; Fingerprint: Gets WMI data known to be used for VM detection via WMIC Queries kernel debugger information...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found