Fix Windows false-positive path-mismatch in safe local file read#25700
Fix Windows false-positive path-mismatch in safe local file read#25700alexmao1024 wants to merge 1 commit intoopenclaw:mainfrom
Conversation
| const devMismatch = stat.dev !== lstat.dev && process.platform !== "win32"; | ||
| if (stat.ino !== lstat.ino || devMismatch) { |
There was a problem hiding this comment.
This approach (skipping dev check entirely on Windows) differs from safe-open-sync.ts:24 which only ignores dev mismatch when either value is 0. Both work for the Windows false-positive issue, but the safe-open-sync.ts approach is more precise since it only relaxes the check when the mismatch is actually happening. Consider aligning with that pattern for consistency:
| const devMismatch = stat.dev !== lstat.dev && process.platform !== "win32"; | |
| if (stat.ino !== lstat.ino || devMismatch) { | |
| const devMismatch = stat.dev !== lstat.dev && !(process.platform === "win32" && (stat.dev === 0 || lstat.dev === 0)); | |
| if (stat.ino !== lstat.ino || devMismatch) { |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/infra/fs-safe.ts
Line: 65-66
Comment:
This approach (skipping `dev` check entirely on Windows) differs from `safe-open-sync.ts:24` which only ignores `dev` mismatch when either value is `0`. Both work for the Windows false-positive issue, but the `safe-open-sync.ts` approach is more precise since it only relaxes the check when the mismatch is actually happening. Consider aligning with that pattern for consistency:
```suggestion
const devMismatch = stat.dev !== lstat.dev && !(process.platform === "win32" && (stat.dev === 0 || lstat.dev === 0));
if (stat.ino !== lstat.ino || devMismatch) {
```
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.|
Superseded by #25917, now merged to What landed from this line of work:
Thank you for surfacing and narrowing the root cause quickly; this directly informed the final landed fix. |
Summary
path-mismatchon Windows caused bydevmismatch betweenhandle.stat()andfs.lstat()for the same file.Root cause
On Windows,
FileHandle.stat()can report a differentdevvalue thanfs.lstat()/fs.stat()for the same file. The current check treats this as a path change and throws, which blocks local media reads (e.g., inbound images).Fix
Gate
devcomparison by platform:process.platform === "win32", only compareino.dev+inocheck.Testing
Local media path is not safe to read/path changed during read.Related
Issue #25699
Greptile Summary
Fixed Windows false-positive
path-mismatcherrors by skippingdevcomparison on Windows platform. On Windows,FileHandle.stat()andfs.lstat()can report differentdevvalues for the same file, causing legitimate file reads to fail. The fix follows the same pattern used insafe-open-sync.ts(commit 04bcabc) which addressed an identical Windowsdevmismatch issue.Confidence Score: 4/5
devmismatch issue and maintains security by continuing to checkinoon all platforms. The implementation follows an established pattern fromsafe-open-sync.ts. However, there's a slight inconsistency in approach: this PR uses&& process.platform !== "win32"whilesafe-open-sync.tsuses|| (process.platform === "win32" && (left.dev === 0 || right.dev === 0)), though both are functionally correct for the Windows case.Last reviewed commit: f9fdf0c
(2/5) Greptile learns from your feedback when you react with thumbs up/down!