On 07/10/2026 05:53, Collin Funk wrote:
There are a few invocations of 'tail', that I don't see any real use for, that can run until your disk space is exhausted.The first one is very simple: $ echo a > a $ timeout -v 1m tail -f a >> a timeout: sending signal TERM to command ‘tail’ $ du --human-readable a 19M a The second one isn't that much more complicated. You just need to figure out the buffer sizes such that appending the bytes will cause subsequent reads never to reach EOF: $ yes a | head -n 4096 | tr -d '\n' > a $ timeout -v 10 tail -c +1 a >> a $ yes a | head -n 4097 | tr -d '\n' > a $ timeout -v 10 tail -c +1 a >> a timeout: sending signal TERM to command ‘tail’ $ du --human-readable a 4.0G a I think it would be better to behave like 'cat' here and catch invocations like this. However, I left this as an RFC without tests or a NEWS entry to get opinions since this likely violates POSIX. For 'cat' it says [1]:
"If the standard output is a regular file, and is the same file as any of the input file operands, the implementation may treat this as an error."
There isn't any mention similar to this for 'tail'. I interpret that as meaning that it should append to the file, even if it simply fills the disk. But perhaps my interpretation is wrong. [1] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/cat.html
I would interpret that as just POSIX not having considered it. I can't think of any use case where this is valid, so it's probably worth adding the protection. Note cat allows `cat empty >> empty`, but tail should not allow that I think as once anything is written it consumes the disk. I've not considered the other cat cases. cheers, Padraig
