Merge pull request #3048 from legnaleurc/fix/rar-reset-lz-table

rar: reset low-distance state for new LZ tables
(cherry picked from commit bede9a3692)
This commit is contained in:
Dustin L. Howett authored and Martin Matuska committed 2026-06-23 11:02:24 +02:00
1 parent 7cbf4a8817
commit d62c81372e
4 files changed
+60

No files matched your search

+1
View File
@@ -971,6 +971,7 @@ libarchive_test_EXTRA_DIST=\
libarchive/test/test_read_format_rar_filter.rar.uu \
libarchive/test/test_read_format_rar_invalid1.rar.uu \
libarchive/test/test_read_format_rar_multi_lzss_blocks.rar.uu \
libarchive/test/test_read_format_rar3_lowdist_reset.rar.uu \
libarchive/test/test_read_format_rar_multivolume.part0001.rar.uu \
libarchive/test/test_read_format_rar_multivolume.part0002.rar.uu \
libarchive/test/test_read_format_rar_multivolume.part0003.rar.uu \
@@ -2409,6 +2409,13 @@ parse_codes(struct archive_read *a)
{
rar_br_consume(br, 1);
/*
* Low-distance repeat state belongs to the current LZ table and
* must not be reused after starting a new table.
*/
rar->lastlowoffset = 0;
rar->numlowoffsetrepeats = 0;
/* Keep existing table flag */
if (!rar_br_read_ahead(a, br, 1))
goto truncated_data;
+36
View File
@@ -592,6 +592,42 @@ DEFINE_TEST(test_read_format_rar_multi_lzss_blocks)
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
DEFINE_TEST(test_read_format_rar3_lowdist_reset)
{
const char reffile[] = "test_read_format_rar3_lowdist_reset.rar";
const unsigned char expected[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x0d, 0x0e,
0x0f, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e,
0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36
};
unsigned char buff[sizeof(expected)];
struct archive_entry *ae;
struct archive *a;
extract_reference_file(reffile);
assert((a = archive_read_new()) != NULL);
assertA(0 == archive_read_support_filter_all(a));
assertA(0 == archive_read_support_format_rar(a));
assertA(0 == archive_read_open_filename(a, reffile, 10240));
assertA(0 == archive_read_next_header(a, &ae));
assertEqualString("lowdist-reset.bin", archive_entry_pathname(ae));
assertEqualInt(sizeof(expected), archive_entry_size(ae));
assertEqualIntA(a, sizeof(expected),
archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff, expected, sizeof(expected));
assertA(1 == archive_read_next_header(a, &ae));
assertEqualInt(1, archive_file_count(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
DEFINE_TEST(test_read_format_rar_compress_best)
{
const char reffile[] = "test_read_format_rar_compress_best.rar";
@@ -0,0 +1,16 @@
begin 644 test_read_format_rar3_lowdist_reset.rar
M4F%R(1H' ,^0<P #0 !J470 @#$ Z@$ $ #W#CX;P =
M-1$ ( &QO=V1I<W0M<F5S970N8FEN$1$1$1$1%55556(B(B(B(B(B(B(B
M(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B
M(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B
M(B(B(B(B9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F
M9F9F9555F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F1$1$1$1$1$541$5
M555555555555555 $" P0%!@<("0H+# T.#Q 1$A,4%187&!D:&QP='A\@(
M2(C)"4F)_(<OD._U8!$1$1$1$155555B(B(B(B(B(B(B(B(B(B(B(B(B(B(B
M(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B
M(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(B(F9F9F9F
M9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F5559F9F9F9
MF9F9F9F9F9F9F9F9F9F9F9F9F9F9F9D1$1$1$1$1%5$1%555555555555555
:?(<!04E166%I<7F!B9&9H:FW5,0]>P! !P
end