[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

tar does not support partial reads

From: Christian Schoenebeck
Subject: tar does not support partial reads
Date: Mon, 19 Jul 2021 14:54:55 +0200


forwarding the following QEMU report to you, as we think it is a bug in tar:

In short: POSIX compliant applications must always expect that read() /
write() functions might read/write less bytes than requested; from
[man 2 read]:


                ... 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:


And tar is expecting safe_read() to always return the exact same amount of
bytes as requested by tar:


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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]