Hi,
forwarding the following QEMU report to you, as we think it is a bug in tar:
https://gitlab.com/qemu-project/qemu/-/issues/409
In short: POSIX compliant applications must always expect that read() /
write() functions might read/write less bytes than requested; from
[man 2 read]:
RETURN VALUE
... It is not an error if this number is smaller than the
number of
bytes requested; this may happen for example because fewer
bytes are
actually available right now (maybe because we were close
to end-
of-file, or because we are reading from a pipe, or from a
terminal), or
because read() was interrupted by a signal. ...
Right now tar is using safe_read() from gnulib which is not handling partial
reads by itself:
https://github.com/coreutils/gnulib/blob/master/lib/safe-read.c
And tar is expecting safe_read() to always return the exact same amount of
bytes as requested by tar:
https://github.com/Distrotech/tar/blob/273975bec1ff7d591d7ab8a63c08a02a285ffad3/src/create.c#L1058
Which can lead to read errors with tar like this:
tar cf /tmp/test.tar -W register.h
tar: register.h: File shrank by 7721 bytes; padding with zeros
register.h: Could only read 4096 of 9728 bytes
One solution would be switching from gnulib's safe_read() to full_read(). I
see from tar's change log though that the opposite actually happened in 1999?
Best regards,
Christian Schoenebeck