BrowserFS
BrowserFS copied to clipboard
(v1.4.3) Stack Overflow(?) when attempting to call readdirSync("./") in Browser
BrowerFS v1.4.3
Code:
BrowserFS.install(window);
BrowserFS.configure({
fs: "LocalStorage"
}, function(e) {
let fs = BrowserFS.BFSRequire("fs");
let files = fs.readdirSync("./");
if (e) {
throw e;
}
});
It appears to be an issue with BrowserFS's internal path library. I haven't tested to see if any other functions are affected but presumably they are.
Only occurs with path "./" Unaffected:
- "/"
- "./foo"
- "/foo"
Ubuntu 18.04
Chrome 74.0.3729.169 (Official Build) (64-bit)
browserfs.min.js:7 Uncaught RangeError: Maximum call stack size exceeded
at String.replace (<anonymous>)
at Function.t._removeDuplicateSeps (browserfs.min.js:7)
at Function.t.dirname (browserfs.min.js:7)
at e.n._findINode (browserfs.min.js:7)
at e.n._findINode (browserfs.min.js:7)
at e.n._findINode (browserfs.min.js:7)
at e.n._findINode (browserfs.min.js:7)
at e.n._findINode (browserfs.min.js:7)
at e.n._findINode (browserfs.min.js:7)
at e.n._findINode (browserfs.min.js:7)
Firefox 67.0 (64-bit)
too much recursion browserfs.min.js:7:29316
RegExpGlobalReplaceShortOpt self-hosted:5052
Symbol.replace self-hosted:4917
replace self-hosted:5801
_removeDuplicateSeps http://127.0.0.1:8080/browserfs.min.js:7
dirname http://127.0.0.1:8080/browserfs.min.js:7
_findINode http://127.0.0.1:8080/browserfs.min.js:7
_findINode http://127.0.0.1:8080/browserfs.min.js:7
_findINode http://127.0.0.1:8080/browserfs.min.js:7
_findINode http://127.0.0.1:8080/browserfs.min.js:7
_findINode http://127.0.0.1:8080/browserfs.min.js:7
_findINode http://127.0.0.1:8080/browserfs.min.js:7
Good find. There's likely a bug in https://github.com/jvilk/bfs-path
This happens in the recursive call at https://github.com/jvilk/BrowserFS/blob/master/src/generic/key_value_filesystem.ts#L561. I'll put out a PR once I have a fix.
So from what i can tell is that path.dirname(path) might return '.' and this will start an infinite loop of trying to get its parent directory INode. The fix would be (i presum) to use process.cwd to get the current directory if the parent directoory is passed as '.'
Can we get this merged?