Fix symlink containment in UbuntuCorpusTrainer.extract() - #2449
Conversation
A duplicated assignment of _DIR_FD_EXTRACTION_SUPPORTED overwrote the first
one and dropped the os.path.isdir('/proc/self/fd') term, so the flag became
true on any POSIX platform with O_NOFOLLOW and dir_fd support.
The dir_fd path builds its extraction root as /proc/self/fd/N, so on macOS
and the BSDs that path does not resolve and extract() aborts on the first
write with OSError: [Errno 30] Read-only file system: '/proc'. That makes
UbuntuCorpusTrainer unusable off Linux rather than just unhardened.
Removing the second assignment restores the guard the comment above it
describes. Added a test asserting the flag implies procfs is present.
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
|
Ran the race against the updated branch. It holds. Same harness as before, swapping Against 24/30, 27/30 and 27/30 before, with 1168, 13472 and 107971 files landing outside. The swap itself still landed on all 90 runs, so that is the anchoring doing the work rather than the harness missing its window. I also forced the flag off to exercise the non-dir_fd path, since that is what macOS and the BSDs take: 0/30 at every size there as well. So the staging directory plus the atomic rename closes it on its own, and the fd anchoring is defence in depth rather than the load-bearing part. Worth knowing if you ever need to simplify. One thing to fix before this merges, which I opened as #2451: |
Keep the procfs check in the dir_fd extraction guard
No description provided.