-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix string corruption in FS entry cache #2055
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
Conversation
| // } | ||
|
|
||
| pub fn addEntry(dir: *DirEntry, entry: std.fs.IterableDir.Entry, allocator: std.mem.Allocator, comptime Iterator: type, iterator: Iterator) !void { | ||
| var _kind: Entry.Kind = undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can tell this is some of the earliest code in bun because i did not know zig very well
| dir_entries_option = rfs.entries.put(&cached_dir_entry_result, .{ | ||
| .entries = Fs.FileSystem.DirEntry.init(dir_path), | ||
| .entries = Fs.FileSystem.DirEntry.init( | ||
| Fs.FileSystem.DirnameStore.instance.append(string, dir_path) catch unreachable, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are few cases where we need to clone this. The caller already cloned it except for the case you're running into, which has to do with automatic package installs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay let me look into that a bit more 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add a debug assertion which checks:
Fs.FileSystem.DirnameStore.instance.isSliceInBuffer(dir_path) or bun.isHeapMemory(dir_path)Then we can find the callers of this function which are not cloning the dir name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is only one user for this function:
Line 1717 in 30e82c5
| if (r.dirInfoForResolution(dir_path_for_resolution, resolved_package_id)) |dir_info_to_use_| { |
string of which is supplied by PackageManager.pathForResolution():Line 1662 in 30e82c5
| const dir_path_for_resolution = manager.pathForResolution(resolved_package_id, resolution, &path_in_global_disk_cache_buf) catch |err| { |
which is using a
threadlocal buffer:Line 260 in 30e82c5
| threadlocal var path_in_global_disk_cache_buf: [bun.MAX_PATH_BYTES]u8 = undefined; |
... doesn't look very cloned to me 😅
|
Thank you |
No description provided.