split: -b and -l ignore short writes, exit 0 with a truncated last chunk
============================================================================
ANT-2026-ZMYL8P2W [NOT SECURITY: ordinary bug]
split: -b and -l ignore short writes, exit 0 with a truncated last chunk
Location: src/uu/split/src/split.rs:403 in custom_write()
Commit: 7bc1eb6d1d6fa2e1dc2c9d2277cf576c05f61e47
============================================================================
Not a security issue. This is a real, reproducible bug that is NOT a security issue: by your project's own policy nobody gains anything from it that they did not already have. It is not part of the vulnerability report, is in none of its counts, needs no embargo and no advisory, and can be filed and fixed in the open like any bug.
When the output volume fills up (or a file size limit is reached) during the final write of a split -b or split -l run, uutils split silently drops the end of the input, up to 8191 bytes, prints nothing and exits 0. GNU split in the same situation reports No space left on device or File too large and exits 1. A script that trusts the exit status, such as split -b 1G dump /spool/dump. && rm dump or a backup under set -e, will treat the truncated chunks as complete.
The cause is custom_write() in src/uu/split/src/split.rs (line 402). It hands each piece of data to the chunk file with a single Write::write(), so one write(2), and returns the count. Nothing writes the remainder. ByteChunkWriter::copy (-b) breaks out of its loop on a short count and abandons the rest of the block. LineChunkWriter::copy (-l) ignores the count entirely. When the last write crosses a page boundary and only part of it fits, the kernel stores what it can and returns a short count. ENOSPC would only come on the next call, and at EOF there is none. A full volume earlier in the stream is still reported one write later, and -C, -n N and -n l/N are unaffected because they already use write_all.
The -b case was introduced in f2c5fec936fb ("split: restore --io-blocksize & remove io::copy (#13643)"), first released in 0.11.0. That commit replaced io::copy, whose write_all loop retried short writes. The -l case comes from 4a6b638453a9 (#13141).
The attached reproducer fills a 1 MiB tmpfs to one page short and runs split -b 64K on a 202608-byte file. GNU split exits 1 with No space left on device, while uutils split exits 0 with empty stderr and its chunks are 1904 bytes short. The same result occurs without a mount under ulimit -f.
Details
This is an ordinary bug, not a security issue: anyone able to fill the output volume can already make the job fail, the bug only makes that failure silent, nobody gains access to anything, and the same truncation happens without anyone's involvement whenever a volume fills up at the wrong byte.
split -b and split -l lose the end of the input without an error when the last write(2) to an output chunk
returns a short count. On a 15-page tmpfs, with an input of seven 8 KiB blocks plus 6000 bytes:
# mount -t tmpfs -o size=60k tmpfs vol
# head -c $((7*8192+6000)) /dev/urandom > in
# target/debug/coreutils split -b 8192 in vol/x. ; echo rc=$? ; cat vol/x.* | wc -c
rc=0
61440 <- 1904 bytes short of the 63344 in `in`, nothing on stderr
# /usr/bin/split -b 8192 in vol/x. ; echo rc=$? (GNU 9.7, same volume, chunks removed in between)
split: vol/x.ah: No space left on device
rc=1
split -l 1 on seven 8192-byte lines followed by one 6000-byte line gives the same result (rc 0, 61440 of 63344
bytes). strace shows why: the eighth chunk needs two pages and one is left, so the kernel stores one page and
reports that; ENOSPC is only returned to a caller that asks again.
uutils: write(5, …, 6000) = 4096
+++ exited with 0 +++
GNU: write(3, …, 6000) = 4096
write(3, …, 1904) = -1 ENOSPC (No space left on device)
The same happens without a mount when the short count comes from a file size limit:
bash -c "trap '' XFSZ; ulimit -f 4; split -b 8192 in6000 x." (6000-byte input) exits 0 with a 4096-byte x.aa;
GNU prints File too large and exits 1.
All data for -b and -l goes through custom_write, which is a single Write::write on platform::Writer,
i.e. one write(2) on the chunk's File (src/uu/split/src/platform/mod.rs:32-34):
// src/uu/split/src/split.rs:402
fn custom_write<T: Write>(bytes: &[u8], writer: &mut T, settings: &Settings) -> io::Result<usize> {
match writer.write(bytes) {
Ok(n) => Ok(n),
Neither caller writes the remaining bytes[n..].
ByteChunkWriter::copy (-b) reaches it through write_chunk (split.rs:595). It looks at the count, but only to
leave the inner loop; the rest of buf is abandoned and the outer loop overwrites io_blk with the next read:
// src/uu/split/src/split.rs:652
if (buf.len() as u64) < self.num_bytes_remaining_in_current_chunk {
let num_bytes_written = self.write_chunk(buf)?;
self.num_bytes_remaining_in_current_chunk -= num_bytes_written as u64;
break; // buf[num_bytes_written..] is gone
}
…
// src/uu/split/src/split.rs:664
let num_bytes_written = self.write_chunk(&buf[..i])?;
…
// It's possible that the underlying writer did not
// write all the bytes.
if num_bytes_written < i {
break; // buf[num_bytes_written..] is gone
}
LineChunkWriter::copy (-l) discards the count, at split.rs:769 and split.rs:783:
custom_write(&buf[prev..=i], &mut self.inner, self.settings)?;
When more input follows a short write, the next write fails with ENOSPC and split exits 1
(split -b 100000 of a 71536-byte file onto the 60k volume above: split: vol/x.aa: No space left on device). So a
short write in the middle of the stream is noticed one call later. When the short write is the last one, read
returns 0, copy returns Ok(()) and the exit status is 0. In the example the first seven write(…, 8192) calls
fill 14 of the 15 pages; the last write(…, 6000) stores 4096 bytes, write_chunk returns 4096, the break at
split.rs:655 drops the other 1904, and the input is at EOF. The loss is always less than one I/O block (8 KiB by
default, split.rs:1399).
The last write is cut short when it crosses a page boundary of its chunk file and no page is free behind that
boundary. With -b 8192, inputs of 3 x 8192 + 4097 and 3 x 8192 + 8191 bytes lose 1 and 4095 bytes with exit
status 0 when the volume is one page short; 3 x 8192 + 4096 gets ENOSPC and exit status 1, because the last write
then fits in one page and is refused as a whole. With -l every line is its own write, so it is the last line
that has to cross a page boundary.
-C, -n N, -n l/N are not affected: they use custom_write_all / write_all and exit 1 with
No space left on device on the same volume.
The -b case was introduced in f2c5fec936fb ("split: restore --io-blocksize & remove io::copy (#13643)",
2026-08-09), first in release 0.11.0; the -l case by the analogous 4a6b638453a9 ("split: remove io::copy for
LineChunkWriter (#13141)", 2026-06-29).
Impact
When the output volume fills up (or a file size limit is reached) during the last write of a split -b or
split -l run, split stores everything except the tail of the input, prints nothing and exits 0; GNU split reports
No space left on device or File too large and exits 1. A script that relies on the exit status
(split -b 1G dump /spool/dump. && rm dump, a backup script under set -e) then treats a truncated set of chunks
as complete, and deletes the original if it is told to do so on success. The loss is up to 8191 bytes, always at the
very end of the input (an archive trailer, the last records of a dump, an appended signature). Users will meet this
rarely: the volume has to run out of space exactly during the final write, and that write has to cross a page
boundary of its chunk file (for -b with a chunk size that is a multiple of 8 KiB: input size modulo 8192 above
4096). A full volume at any earlier point is still reported, one write later. The reproducer has a second account
fill a shared tmpfs to one page short only to make that timing deterministic. Only tmpfs and RLIMIT_FSIZE were
tested as sources of the short count.
Related: dd has the same class of bug, reported separately (Output::write_block in src/uu/dd/src/dd.rs retries a
short write only under iflag=fullblock). It shares no code with split, and the attached patch does not change it.
Reproducing
Run repro as root (it mounts a tmpfs) with repro.d/ at /tmp/repro.d. It runs the prebuilt
target/debug/coreutils and GNU split 9.7 from /usr/bin. Nothing is compiled.
reprodoes the setup, plays root's job and decides.- Setup: in a temp directory it mounts a 1 MiB tmpfs with mode 1777. This is the shared volume, like
/var/tmp. Outside that volume it writes root'sdb.dump, mode 0600, made of 3 x 64 KiB + 6000 random bytes. With-b 64K, split's lastwrite(2)is 6000 bytes long, so it needs two 4 KiB pages. - Root's job:
split -b 64K db.dump shared-volume/db.dump., run once with GNU split and then once with uutils split on the same filled volume. After each run the script saves the exit status and stderr, joins the chunks and deletes them, so both runs start with the same free space.
- Setup: in a temp directory it mounts a 1 MiB tmpfs with mode 1777. This is the shared volume, like
repro.d/fill_shared_volume.pyis the unprivileged user's part and runs asnobody:nogroupwith no supplementary groups. It reads the script from stdin, so it does not need read access to the file. It usesstatvfson the volume andstatondb.dump, which gives it the size but not the content. With the chunk size it works out that the job needs 50 pages, then writes its own file so that 49 pages are left free.
Expected output:
db.dump is 202608 bytes
CONTROL GNU split: exit status 1, stderr 'split: /tmp/split-short-write-…/shared-volume/db.dump.ad: No space left on device\n', chunks hold 200704 bytes
OBSERVED uutils split: exit status 0, stderr '', chunks hold 200704 bytes
BUG
Both programs can store only 200704 bytes. GNU split reports that it failed. uutils split exits 0 and prints nothing,
but 1904 bytes are missing. The script stops with an error and prints no verdict if the GNU control does not hit
No space left on device, because that means the volume was not filled as intended. It prints BUG only when
uutils split exits 0 with empty stderr and the joined chunks are a proper prefix of the bytes written to db.dump.
Suggested fix
The attached patch removes custom_write (src/uu/split/src/split.rs:402) and sends all -b and -l output
through the existing custom_write_all, which uses write_all and handles BrokenPipe under --filter the same
way custom_write did. A short count is then followed by a write of the remainder, which returns the error behind it
(No space left on device, File too large) and makes split exit 1, as GNU split does; EINTR is now retried
instead of being fatal. ByteChunkWriter::write_chunk (split.rs:595) returns io::Result<()>, and
ByteChunkWriter::copy subtracts the full length it handed over; the now-impossible short-count handling, including
the num_bytes_written < i branch at split.rs:669, is deleted. LineChunkWriter::copy calls custom_write_all
at split.rs:769 and split.rs:783. -C, -n N and -n l/N already used custom_write_all and are unchanged.
The patch also adds test_short_last_write_is_reported to tests/by-util/test_split.rs: with the file size limit
at 4096 bytes (.limit(Resource::Fsize, CAP, CAP).ignore_sigxfsz(), as in tests/by-util/test_dd.rs:2423),
split -b 8192 and split -l 1 on 6000 bytes of stdin must exit 1 with File too large and leave a 4096-byte
xaa. Applied to a clean checkout and rebuilt, the patch makes the reproducer print OK, and a --filter command
that closes its stdin early still exits 0.
Running the reproducer
bugs-not-security/ANT-2026-ZMYL8P2W/repro, next to this file, with its companion files in bugs-not-security/ANT-2026-ZMYL8P2W/repro.d/ (fill_shared_volume.py) — the script reads them from /tmp/repro.d/. It was written by an automated agent and our check ran it as root in a privileged container: run it INSIDE A THROWAWAY VM, with the image oss-scan-7bc1eb6d1d6f built by bash build/build-image.sh, from the archive's top directory:
docker run --rm --network=none --privileged -u 0 -w /src -v "$PWD/bugs-not-security/ANT-2026-ZMYL8P2W/repro:/tmp/repro:ro" -v "$PWD/bugs-not-security/ANT-2026-ZMYL8P2W/repro.d:/tmp/repro.d:ro" oss-scan-7bc1eb6d1d6f /tmp/repro
It prints its evidence; the last line is BUG if the issue triggered, OK otherwise.
Hi! I'd like to work on this. Could you assign it to me?
I'll make the -b/-l writer in split handle short writes (write the full buffer or fail) so it reports an error instead of exiting 0 with a truncated chunk, and add a test.
I'll keep the PR small and focused on this issue.