When sort spills sorted chunks to temporary files during an external sort (any time the input exceeds the sort buffer), it writes each chunk with write_all(...).unwrap(). If that temp-file write fails — e.g. the -T temp directory is on a full or size-limited filesystem — the unwrap() panics.
This is distinct from #13653 ("sort aborts … when the output write fails during a merge"): that was the output write path (merge.rs) and was fixed by #13654, which touched only merge.rs. The temp-file spill write in ext_sort/threaded.rs was not covered and still aborts at current main.
Steps to reproduce
Point -T at a small filesystem and force a spill with a tiny buffer (-S 0).
Using a 1 MiB tmpfs as the temp dir; output goes to /dev/null, so it is the
temp-file write that fails, not the output:
$ # ~18 MB of shuffled lines
$ python3 -c "import random; open('big.txt','w').write(''.join(f'{random.randint(0,10**9):09d}-padding-payload\n' for _ in range(400000)))"
$ # temp dir on a 1 MiB tmpfs (e.g. mount -t tmpfs -o size=1m tmpfs /st)
$ sort -S 0 -T /st big.txt -o /dev/null
thread 'main' panicked at src/uu/sort/src/ext_sort/threaded.rs:302:34:
called `Result::unwrap()` on an `Err` value: Os { code: 28, kind: StorageFull, message: "No space left on device" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Aborted (core dumped)
$ echo $?
134
Root cause
The chunk-spill writer unwraps every temp-file write:
|
fn write_lines<T: Write>(lines: &[Line], writer: &mut T, separator: u8) { |
|
for s in lines { |
|
writer.write_all(s.line).unwrap(); |
|
writer.write_all(&[separator]).unwrap(); |
|
} |
|
} |
When
sortspills sorted chunks to temporary files during an external sort (any time the input exceeds the sort buffer), it writes each chunk withwrite_all(...).unwrap(). If that temp-file write fails — e.g. the-Ttemp directory is on a full or size-limited filesystem — theunwrap()panics.This is distinct from #13653 ("sort aborts … when the output write fails during a merge"): that was the output write path (
merge.rs) and was fixed by #13654, which touched onlymerge.rs. The temp-file spill write inext_sort/threaded.rswas not covered and still aborts at currentmain.Steps to reproduce
Point
-Tat a small filesystem and force a spill with a tiny buffer (-S 0).Using a 1 MiB tmpfs as the temp dir; output goes to
/dev/null, so it is thetemp-file write that fails, not the output:
Root cause
The chunk-spill writer unwraps every temp-file write:
coreutils/src/uu/sort/src/ext_sort/threaded.rs
Lines 300 to 305 in 5426f41