Merge pull request #3229 from stoeckmann/cab_e8

This commit is contained in:
Dustin L. Howett authored and GitHub committed 2026-07-03 13:38:20 -05:00
commit 5933c80ae5
5 files changed
+70 -1

No files matched your search

+2
View File
@@ -486,6 +486,7 @@ libarchive_test_SOURCES= \
libarchive/test/test_read_format_ar.c \
libarchive/test/test_read_format_cab.c \
libarchive/test/test_read_format_cab_filename.c \
libarchive/test/test_read_format_cab_lzx_e8.c \
libarchive/test/test_read_format_cab_lzx_oob.c \
libarchive/test/test_read_format_cab_mszip_oob.c \
libarchive/test/test_read_format_cab_multi.c \
@@ -904,6 +905,7 @@ libarchive_test_EXTRA_DIST=\
libarchive/test/test_read_format_cab_2.cab.uu \
libarchive/test/test_read_format_cab_3.cab.uu \
libarchive/test/test_read_format_cab_filename_cp932.cab.uu \
libarchive/test/test_read_format_cab_lzx_e8.cab.uu \
libarchive/test/test_read_format_cab_lzx_oob.cab.uu \
libarchive/test/test_read_format_cab_multi.p1.cab.uu \
libarchive/test/test_read_format_cab_multi.p2.cab.uu \
+2 -1
View File
@@ -204,6 +204,7 @@ struct lzx_stream {
/* Limits */
#define MAX_UNCOMPRESS_SIZE 0x8000
#define MAX_FILE_SIZE (UINT16_MAX * MAX_UNCOMPRESS_SIZE)
#define MAX_E8_TRANSLATION (0x8000 * MAX_UNCOMPRESS_SIZE)
static const char * const compression_name[] = {
"NONE",
@@ -2217,7 +2218,7 @@ lzx_translation(struct lzx_stream *strm, unsigned char *buffer, size_t size,
struct lzx_dec *ds = strm->ds;
unsigned char *p, *end;
if (!ds->translation || size <= 10)
if (!ds->translation || offset >= MAX_E8_TRANSLATION || size <= 10)
return;
p = buffer;
+1
View File
@@ -115,6 +115,7 @@ IF(ENABLE_TEST)
test_read_format_ar.c
test_read_format_cab.c
test_read_format_cab_filename.c
test_read_format_cab_lzx_e8.c
test_read_format_cab_lzx_oob.c
test_read_format_cab_mszip_oob.c
test_read_format_cab_multi.c
@@ -0,0 +1,59 @@
/*-
* 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_format_cab_lzx_e8)
{
const char *refname = "test_read_format_cab_lzx_e8.cab";
struct archive *a;
struct archive_entry *ae;
char buff[30];
extract_reference_file(refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_cab(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
assertEqualIntA(a, ARCHIVE_OK,
archive_read_open_filename(a, refname, 10240));
/* Read first entry. */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualString(archive_entry_pathname(ae), "e8.bin");
assertEqualInt(archive_entry_size(ae), 30);
/* Verify that E8 translation works. */
assertEqualIntA(a, sizeof(buff),
archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff, "\xE8\x00\x00\x00\x00", 5);
assertEqualMem(buff + 5, "\xE8\x00\x00\x00\x80", 5);
assertEqualMem(buff + 10, "\xE8\xFF\xFF\xFF\x7F", 5);
assertEqualMem(buff + 15, "\xE8\xFF\x00\x00\x00", 5);
assertEqualMem(buff + 20, "\xE8\x12\x34\x56\x78", 5);
assertEqualMem(buff + 25, "\xE8\x87\x65\x43\x21", 5);
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
@@ -0,0 +1,6 @@
begin 644 test_read_format_cab_lzx_e8.cab.uu
M35-#1@````!]`````````"P``````````P$!``$`````````0P````$``P\>
M````````````XUQ,BB``93@N8FEN`,J?6J@R`!X`6X"`C0`PX`$/`````0``
C``4```#H`````.@```"`Z/___W_H#@$``.@2-%9XZ(=E0R$`
`
end