]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Merge pull request #2665 from stoeckmann/read_data_sparse
authorMartin Matuška <martin@matuska.de>
Thu, 12 Jun 2025 08:54:08 +0000 (10:54 +0200)
committerMartin Matuska <martin@matuska.de>
Wed, 10 Sep 2025 08:14:46 +0000 (10:14 +0200)
archive_read_data: Handle sparse holes at end of file correctly

(cherry picked from commit c3be70e0711b273bfa4f8dc41b8a88848473cec8)

libarchive/archive_read.c
libarchive/archive_read_support_format_rar.c
libarchive/archive_read_support_format_warc.c
libarchive/archive_read_support_format_xar.c

index 50db87017706c565adb2813250ca7dcd5ff5c3e5..ea58c6ed0123c479ab2767799f30fd9a0ac60f30 100644 (file)
@@ -834,7 +834,9 @@ archive_read_data(struct archive *_a, void *buff, size_t s)
                        r = archive_read_data_block(a, &read_buf,
                            &a->read_data_remaining, &a->read_data_offset);
                        a->read_data_block = read_buf;
-                       if (r == ARCHIVE_EOF)
+                       if (r == ARCHIVE_EOF &&
+                           a->read_data_offset == a->read_data_output_offset &&
+                           a->read_data_remaining == 0)
                                return (bytes_read);
                        /*
                         * Error codes are all negative, so the status
index 923ae5c65e1744214539fe812d96b47cee8ce7a2..04dff5b6c3a34379af8e0a494de161995f00b286 100644 (file)
@@ -1117,8 +1117,6 @@ archive_read_format_rar_read_data(struct archive_read *a, const void **buff,
   if (rar->entry_eof || rar->offset_seek >= rar->unp_size) {
     *size = 0;
     *offset = rar->offset;
-    if (*offset < rar->unp_size)
-      *offset = rar->unp_size;
     return (ARCHIVE_EOF);
   }
 
index 696f959c341dc9c9c317ad6103c5a0f71862a137..d8f188cf0b44909e0803a9f82a2cab27f9ae2f0f 100644 (file)
@@ -405,7 +405,7 @@ _warc_read(struct archive_read *a, const void **buf, size_t *bsz, int64_t *off)
                /* it's our lucky day, no work, we can leave early */
                *buf = NULL;
                *bsz = 0U;
-               *off = w->cntoff + 4U/*for \r\n\r\n separator*/;
+               *off = w->cntoff;
                w->unconsumed = 0U;
                return (ARCHIVE_EOF);
        }
index b4e1192ef771026423517be6de9ca0a7fc46dda7..36b5ab3ae04c8508d2376cc5f477c3f2e8b4a399 100644 (file)
@@ -930,7 +930,7 @@ xar_read_data(struct archive_read *a,
 abort_read_data:
        *buff = NULL;
        *size = 0;
-       *offset = xar->total;
+       *offset = (int64_t)xar->entry_total;
        return (r);
 }