Repository navigation
Commit 2e79e37
committed
file-safety: authorize by bigint file identity, not by a rounded number
The commit-time guard compared dev and ino as numbers. Both sides came from a plain stat, and a plain
stat hands back a 64-bit NTFS file id rounded to a double: above 2**53 two different files can round to
the same number, and the guard would then accept one for the other, which is exactly the swap it exists
to catch. The lost bits cannot be recovered from the rounded value, so the fix is the capture spelling,
not a smarter comparison: the option is now { dev: bigint; ino: bigint } and the guard reads the target
with fs.stat(targetPath, { bigint: true }).
The option has no production caller in this tree - the only seven mentions of authorizedTarget at
5559f1f are the option declaration, the three guard lines, and the three rows in
safeWriteText.identity.spec.ts - so this is the moment the spelling is free to change, and it is the
last moment it will be free once sibling units start handing identities in. Measured on this box's NTFS
volume, three identities came back as 281474990289684, 4503599627490809 and 5629499534337367, all
below 2**53: this volume cannot exhibit the collision, so no row here asserts the rounding, and the
rows are updated to read bigint identities rather than being asked to prove something the filesystem
will not do for them.
Verification, pinned node v22.23.4 with stdio on file descriptors: services/file-safety with
utils/__tests__/safeWriteJson.test.ts is 133 passed and 1 skipped (the mode row skipped on win32, as
before) in 4 files; tsc --noEmit -p tsconfig.json in src reports 0 errors; eslint --prune-suppressions
--max-warnings=0 exits 0 on both touched files and its suppressions rewrite was reverted; prettier
--check is clean on both, and formatting was done before measuring. Gate: 496 of 500 counted
executable lines at base 73931fe with base...head and --unified=0,
against 496 at 5559f1f - a 0-line move, because the type line and the comments are not executable -
measured with v22.23.4.1 parent 5559f1f commit 2e79e37
2 files changed
Lines changed: 19 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| |||
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
26 | | - | |
| 30 | + | |
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
| |||
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
43 | | - | |
| 47 | + | |
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
| |||
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
56 | | - | |
| 60 | + | |
57 | 61 | | |
58 | 62 | | |
59 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
22 | 31 | | |
23 | | - | |
| 32 | + | |
24 | 33 | | |
25 | 34 | | |
26 | 35 | | |
| |||
749 | 758 | | |
750 | 759 | | |
751 | 760 | | |
752 | | - | |
| 761 | + | |
753 | 762 | | |
754 | 763 | | |
755 | 764 | | |
| |||
0 commit comments