Repository navigation
FileSystemRouter: fix a panic and wrong route names for an absolute dir with '..' in it - #44342
Conversation
|
Updated 6:28 PM PT - Sep 30th, 2026
🔄 @dylan-conway, the build for |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: oven-sh/bun/.coderabbit.yaml Review profile: ASSERTIVE Plan: Essentials Run ID: 📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review. WalkthroughThe filesystem router constructor now joins absolute and relative directory values against the filesystem top-level directory. A subprocess test compares routes from an absolute path containing ChangesFilesystem router path resolution
Suggested reviewers: Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to No actionable merge-blocking risk is identified for the path-normalization change. The regression test exercises the intended path spelling; normal build and test checks should complete before merging. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
…tem does (parked) Not proposed for merge. This is the rest of the change that #47454 took Bun.mmap from. It moves a relative Bun.Glob `cwd` and the FileSystemRouter `dir` from the text reading of `<symlink>/..` to the system's reading, and makes absolute glob results behind a `..` name the directory that was listed. It waits for a decision. #44342 records the text fold for the router's `dir`, and #45800 pins the same fold for `--cwd` with tests. Review items that are still open in this commit: - make the walker check opt-in for Bun.Glob, or own the `bun lint` change - return the error of the check and do not fall back to the folded text - do not name the directory with libc realpath - move the router check into load_router, so that reload() repeats it - take `\` as a separator at the router, as its join does - add rows for a literal pattern and for a folded text that does not exist
What does this PR do?
Fixes
panic: range start index 123 out of range for slice of length 119innew Bun.FileSystemRouter()(RouteLoader::load, Sentry BUN-564Q and BUN-54X5, 7 reports on 1.4.2), and the wrong route names the same bug gives when it does not panic.Trigger
An absolute
dirwith..in it, which is whatimport.meta.dir + "/../pages"is:7fe13e1b9pages/index.tsx//pages/api/x.tsx/api/xpages/a-long-directory-name/deeper/page.tsx/ng-directory-name/deeper/page/a-long-directory-name/deeper/pageCause
A route is named by what follows the router's directory in the directory of its file:
&entry_dir[base_dir.len() - 1..]. The router enters each subdirectory by a normalized path, so that is how the directory of a nested file is spelled.The constructor normalized a relative
dir, by joining it to the working directory. An absolutedirwas used as written, with only repeated separators collapsed. With..in it, it is longer than the normalized path, so for a nested file the slice starts too far in: inside a directory name, or past the end when the path below the router's directory is shorter than what..folds away.Fix
Both kinds go through the same join, which takes an absolute part as it is and normalizes it. It is the length-checked one, since the string comes from the user. A
dirtoo long for the buffer gets the constructor'sUnable to find directoryerror.How did you verify your code works?
A new test in
filesystem_router.test.tsthat compares the routes of both spellings of one directory, with the three files above.panic: range start index 35 out of range for slice of length 31filesystem_router.test.ts: 36 pass on the debug build.Relative paths with
..,.or doubled separators, absolute paths with doubled separators, and symlinked directories already gave the right routes on canary...after a symlink is folded as text, as it already was for a relativedir. It did not work for an absolute one before. With/app/linka symlink to/srv/x, routes in/srv/pages, anddir: "/app/link/../pages":7fe13e1b9/app/pagesENOENT opening route: /app/pages/index.tsxUnable to find directory: /app/pagesUnable to find directory: /app/pages/app/pagesexistsENOENT/app/pages/app/pages