Repository navigation
Commit e7b0650
Python: Do not let filesystem grep read through a swapped symlink
From Copilot review 5111742587.
_search_files_sync read each candidate with entry.read_bytes(), which reopens by
path after _enumerate_search_files has already screened it for links. A candidate
replaced with a symlink in between was followed, so grep could return content from
outside the store root -- and it bypassed the O_NOFOLLOW reader the store's own
read() goes through. The read now uses that reader, and re-screens the entry
immediately before it: O_NOFOLLOW closes the window atomically where the platform
has it, and the re-screen narrows it on Windows, where os.O_NOFOLLOW does not
exist and degrades to 0. The race is narrowed rather than eliminated there, which
is worth knowing rather than glossing.
The handler had to widen with it. _read_file_sync reports non-UTF-8 content and a
symlinked path as ValueError and a vanished file as OSError, none of which the
existing except UnicodeDecodeError caught, so a single bad entry would have
aborted the whole search instead of being skipped. Two log assertions move with
the reworded message.
Two dead helpers also go: _SkewedStore and _MemorySkewedStore were left behind
when the alignment tests were removed, referenced by nothing. Ruff could not see
them -- an unused module-level class is not a lint error -- but removing
_MemorySkewedStore made ruff flag the FileSearchMatch and FileSearchResult imports
it had been keeping alive, which is how the review described it.
The symlink test stages both halves of the race rather than creating a link,
because a real symlink needs privileges this suite cannot rely on: it skipped
here, which is exactly how it would have passed while proving nothing. Staged, it
runs everywhere and returns the outside content without the fix.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>1 parent 6dfea3c commit e7b0650
3 files changed
Lines changed: 47 additions & 59 deletions
File tree
- python/packages/core
- agent_framework/_harness
- tests/core
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1363 | 1363 | | |
1364 | 1364 | | |
1365 | 1365 | | |
1366 | | - | |
1367 | | - | |
1368 | | - | |
1369 | | - | |
1370 | | - | |
1371 | | - | |
1372 | | - | |
1373 | | - | |
1374 | | - | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
1375 | 1385 | | |
1376 | 1386 | | |
1377 | 1387 | | |
1378 | 1388 | | |
1379 | 1389 | | |
1380 | 1390 | | |
1381 | 1391 | | |
1382 | | - | |
| 1392 | + | |
1383 | 1393 | | |
1384 | 1394 | | |
1385 | 1395 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
321 | 346 | | |
322 | 347 | | |
323 | 348 | | |
| |||
955 | 980 | | |
956 | 981 | | |
957 | 982 | | |
958 | | - | |
959 | | - | |
| 983 | + | |
| 984 | + | |
960 | 985 | | |
961 | 986 | | |
962 | 987 | | |
| |||
1513 | 1538 | | |
1514 | 1539 | | |
1515 | 1540 | | |
1516 | | - | |
1517 | | - | |
1518 | | - | |
1519 | | - | |
1520 | | - | |
1521 | | - | |
1522 | | - | |
1523 | | - | |
1524 | | - | |
1525 | | - | |
1526 | | - | |
1527 | | - | |
1528 | | - | |
1529 | | - | |
1530 | | - | |
1531 | | - | |
1532 | | - | |
1533 | | - | |
1534 | | - | |
1535 | | - | |
1536 | | - | |
1537 | | - | |
1538 | | - | |
1539 | | - | |
1540 | 1541 | | |
1541 | 1542 | | |
1542 | 1543 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
| |||
495 | 493 | | |
496 | 494 | | |
497 | 495 | | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | 496 | | |
520 | 497 | | |
521 | 498 | | |
| |||
0 commit comments