Merge commit from fork

read: Fix memory corruption on filtered multi-volume archives
(cherry picked from commit 68b69249de)
This commit is contained in:
Tobias Stoeckmann authored and Martin Matuska committed 2026-06-23 10:53:47 +02:00
1 parent 5bc5b344bb
commit 03125f866f
6 files changed
+79 -22

No files matched your search

+3
View File
@@ -467,6 +467,7 @@ libarchive_test_SOURCES= \
libarchive/test/test_read_disk_entry_from_file.c \
libarchive/test/test_read_extract.c \
libarchive/test/test_read_file_nonexistent.c \
libarchive/test/test_read_files_compressed.c \
libarchive/test/test_read_filter_compress.c \
libarchive/test/test_read_filter_grzip.c \
libarchive/test/test_read_filter_gzip_recursive.c \
@@ -819,6 +820,8 @@ libarchive_test_EXTRA_DIST=\
libarchive/test/test_rar_multivolume_uncompressed_files.part08.rar.uu \
libarchive/test/test_rar_multivolume_uncompressed_files.part09.rar.uu \
libarchive/test/test_rar_multivolume_uncompressed_files.part10.rar.uu \
libarchive/test/test_read_files_compressed.part01.uu \
libarchive/test/test_read_files_compressed.part02.uu \
libarchive/test/test_read_filter_grzip.tar.grz.uu \
libarchive/test/test_read_filter_gzip_recursive.gz.uu \
libarchive/test/test_read_filter_lrzip.tar.lrz.uu \
+19 -22
View File
@@ -252,42 +252,39 @@ client_close_proxy(struct archive_read_filter *self)
return read_client_close_proxy(self->archive);
}
static int
client_open_proxy(struct archive_read_filter *self)
{
int r = ARCHIVE_OK;
if (self->archive->client.opener != NULL)
r = (self->archive->client.opener)(
(struct archive *)self->archive, self->data);
return (r);
}
static int
client_switch_proxy(struct archive_read_filter *self, unsigned int iindex)
{
int r1 = ARCHIVE_OK, r2 = ARCHIVE_OK;
void *data2 = NULL;
struct archive_read *a;
int r1 = ARCHIVE_OK, r2 = ARCHIVE_OK;
void *data2;
while (self->upstream != NULL)
self = self->upstream;
a = self->archive;
/* Don't do anything if already in the specified data node */
if (self->archive->client.cursor == iindex)
if (a->client.cursor == iindex)
return (ARCHIVE_OK);
self->archive->client.cursor = iindex;
data2 = self->archive->client.dataset[self->archive->client.cursor].data;
if (self->archive->client.switcher != NULL)
a->client.cursor = iindex;
data2 = a->client.dataset[a->client.cursor].data;
if (a->client.switcher != NULL)
{
r1 = r2 = (self->archive->client.switcher)
((struct archive *)self->archive, self->data, data2);
r1 = r2 = (a->client.switcher)
((struct archive *)a, self->data, data2);
self->data = data2;
}
else
{
/* Attempt to call close and open instead */
if (self->archive->client.closer != NULL)
r1 = (self->archive->client.closer)
((struct archive *)self->archive, self->data);
if (a->client.closer != NULL)
r1 = (a->client.closer)
((struct archive *)a, self->data);
self->data = data2;
r2 = client_open_proxy(self);
if (a->client.opener != NULL)
r2 = (a->client.opener)
((struct archive *)a, self->data);
}
return (r1 < r2) ? r1 : r2;
}
+1
View File
@@ -99,6 +99,7 @@ IF(ENABLE_TEST)
test_read_disk_entry_from_file.c
test_read_extract.c
test_read_file_nonexistent.c
test_read_files_compressed.c
test_read_filter_compress.c
test_read_filter_grzip.c
test_read_filter_gzip_recursive.c
@@ -0,0 +1,48 @@
/*-
* Copyright (c) 2026 Tobias Stoeckmann
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
DEFINE_TEST(test_read_files_compressed)
{
const char *reffiles[] =
{
"test_read_files_compressed.part01",
"test_read_files_compressed.part02",
NULL
};
struct archive *a;
struct archive_entry *entry = NULL;
extract_reference_files(reffiles);
assert((a = archive_read_new()) != NULL);
assertA(0 == archive_read_support_filter_all(a));
assertA(0 == archive_read_support_format_all(a));
assertA(0 == archive_read_open_filenames(a, reffiles, 10240));
assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &entry));
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
}
@@ -0,0 +1,4 @@
begin 644 test_read_files_compressed.part01
"'YT`
`
end
@@ -0,0 +1,4 @@
begin 644 test_read_files_compressed.part02
!````
`
end