Skip to content
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

Errors working with certain path names #938

Closed
dmurvihill opened this issue Aug 7, 2023 · 1 comment · Fixed by #945
Closed

Errors working with certain path names #938

dmurvihill opened this issue Aug 7, 2023 · 1 comment · Fixed by #945

Comments

@dmurvihill
Copy link

Implement the following test (written in TS/Jest; not sure what your stack looks like but it shouldn't be too hard to adapt):

it('should allow directories named __proto__', async () => {
  const dirName = '/__proto__';
  expect(await dirExists(dirName)).toBe(false);
  await memfs.fs.promises.mkdir(dirName);
  try {
    expect(await dirExists(dirName)).toBe(true);
  } finally {
    await memfs.fs.promises.rmdir(dirName);
  }
});

function dirExists(path: string): Promise<boolean> {
  return memfs.fs.promises
    .access(path, memfs.fs.promises.constants.R_OK)
    .then(() => true)
    .catch(() => false);
}

Result:

Error: ENOENT: no such file or directory, rmdir '/__proto__'

    at createError (C:\Users\d\IdeaProjects\big-shuffle\node_modules\memfs\src\node\util.ts:138:17)
    at Volume.getLinkOrThrow (C:\Users\d\IdeaProjects\big-shuffle\node_modules\memfs\src\volume.ts:404:33)
    at Volume.getLinkAsDirOrThrow (C:\Users\d\IdeaProjects\big-shuffle\node_modules\memfs\src\volume.ts:453:23)
    at Volume.rmdirBase (C:\Users\d\IdeaProjects\big-shuffle\node_modules\memfs\src\volume.ts:1628:23)
    at Immediate.<anonymous> (C:\Users\d\IdeaProjects\big-shuffle\node_modules\memfs\src\volume.ts:516:25)
    at processImmediate (node:internal/timers:478:21)

The analogous test on the real fs/promises is passing.

This was only tested with /__proto__ as the directory name, but there may be other affected names and functions.

Thanks to fast-check for finding this bug.

@G-Rath
Copy link
Collaborator

G-Rath commented Aug 7, 2023

I expect __proto__ is probably the only one, and it'll be because we're using a plain object to track the filesystem which ignores assignments to __proto__.

It might just be a matter of using Object.create(null) instead of {} 🤔

@G-Rath G-Rath added the bug label Aug 7, 2023
SukkaW added a commit to SukkaW/memfs that referenced this issue Aug 19, 2023
G-Rath added a commit that referenced this issue Sep 15, 2023
* fix(#938): replace `children` plain object with Map

* test: apply code review suggestion from @G-Rath

* chore: appy `prettier`

---------

Co-authored-by: Gareth Jones <[email protected]>
github-actions bot pushed a commit that referenced this issue Sep 15, 2023
## [4.2.2](v4.2.1...v4.2.2) (2023-09-15)

### Bug Fixes

* support directories named `__proto__` ([#945](#945)) ([8d92a0b](8d92a0b)), closes [#938](#938)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants