This is what my work collegue proposes.  Works for us.

Acceptable hack Denys?

AFAICT, this checks the tar archive after decompression, only.
The "tar: invalid magic" error needs to be handled separatelly.
GNU tar reports:

        gzip: stdin: unexpected end of file
        tar: Child returned status 1
        tar: Error is not recoverable: exiting now

and exit status 2.

The busybox version of tar does not return error when encountering
an invalid archive. The behaviour has changed between IR1.18 and
IR1.20, but both versions fail to return an error upon failure
for uncompressed archives.
This fix solves the problem for IR1.20. For IR1.18 another solution
is required and the tar command will now return code 2 for empty or
invalid archives.

Signed-off-by: Magnus Rolf <[email protected]>
---
 busybox/archival/libarchive/get_header_tar.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/busybox/archival/libarchive/get_header_tar.c 
b/busybox/archival/libarchive/get_header_tar.c
index b168653..54ddb19 100644
--- a/busybox/archival/libarchive/get_header_tar.c
+++ b/busybox/archival/libarchive/get_header_tar.c
@@ -190,17 +190,14 @@ char FAST_FUNC get_header_tar(archive_handle_t 
*archive_handle)
        /* to prevent misdetection of bz2 sig */
        *(aliased_uint32_t*)&tar = 0;
        i = full_read(archive_handle->src_fd, &tar, 512);
-       /* If GNU tar sees EOF in above read, it says:
-        * "tar: A lone zero block at N", where N = kilobyte
-        * where EOF was met (not EOF block, actual EOF!),
-        * and exits with EXIT_SUCCESS.
-        * We will mimic exit(EXIT_SUCCESS), although we will not mimic
-        * the message and we don't check whether we indeed
-        * saw zero block directly before this. */
-       if (i == 0) {
-               xfunc_error_retval = 0;
+       /* Since v1.19, GNU tar exits with code 2 when supplied an archive 
smaller
+        * than 512 bytes in reading mode (-x, -t).
+        * Previous tar versions silently ignored it, exiting with code 0.
+        */
+       if (i < 512) {
+               xfunc_error_retval = 2;
  short_read:
-               bb_error_msg_and_die("short read");
+               bb_error_msg_and_die("This does not look like a tar archive");
        }
        if (i != 512) {
                IF_FEATURE_TAR_AUTODETECT(goto autodetect;)
-- 
1.8.4.2


Cheers,

-- 
Cristian
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to