Fix MemoryFileSystem._internal_path prefix stripping corruption - #429
Draft
rootkiller6788 wants to merge 1 commit into
Draft
Fix MemoryFileSystem._internal_path prefix stripping corruption#429rootkiller6788 wants to merge 1 commit into
rootkiller6788 wants to merge 1 commit into
Conversation
str.lstrip treats its argument as a set of characters, so
resolve_path(path).lstrip('/mem/') also strips any leading 'm'/'e'
characters after the prefix. This corrupts path components that begin
with those characters: /mem/models becomes 'odels' and /mem/eval becomes
'val', and /mem/models collides with the distinct path /mem/odels.
Replace it with an explicit prefix check plus slice, and keep mapping
the bare prefix ('/mem') to the root. Add a regression test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
MemoryFileSystem._internal_pathstripped the/mem/prefix with:str.lstriptreats its argument as a set of characters, not a literal prefix. So any leadingmorecharacters after the prefix were also stripped, corrupting path components:/mem/models/a/odels/a/mem/eval/b/val/b/mem/memory/oryThis is observable via
listdir(fs.mkdirs('/mem/models/a')thenfs.listdir('/mem')returns['odels']instead of['models']) and causes distinct paths such as/mem/modelsand/mem/odelsto collide.Fix
Replace
lstripwith an explicitstartswithcheck plus a slice, and keep mapping the bare prefix/memto the root:Tests
Added
MemoryFileSystemTest.test_internal_path_prefix_stripping, which verifies thatm/e-prefixed components are preserved, and that/mem/modelsand/mem/odelsremain distinct.