aboutsummaryrefslogtreecommitdiffstats
path: root/libarchive/test
diff options
context:
space:
mode:
Diffstat (limited to 'libarchive/test')
-rw-r--r--libarchive/test/test_entry.c2
-rw-r--r--libarchive/test/test_read_format_rar5.c26
-rw-r--r--libarchive/test/test_read_format_xar.c10
-rw-r--r--libarchive/test/test_read_format_zip.c66
-rw-r--r--libarchive/test/test_read_format_zip_bz2_hang.zip.uu5
-rw-r--r--libarchive/test/test_read_format_zip_ppmd8_crash_1.zipx.uu4
-rw-r--r--libarchive/test/test_read_format_zip_ppmd8_crash_2.zipx.uu4
7 files changed, 97 insertions, 20 deletions
diff --git a/libarchive/test/test_entry.c b/libarchive/test/test_entry.c
index 0ccc9e8fb355..a0a2607a156c 100644
--- a/libarchive/test/test_entry.c
+++ b/libarchive/test/test_entry.c
@@ -336,7 +336,7 @@ DEFINE_TEST(test_entry)
/* Converting fflags bitmap to string is currently system-dependent. */
/* TODO: Make this system-independent. */
assertEqualString(archive_entry_fflags_text(e),
- "uappnd,nouchg,nodump,noopaque,uunlnk");
+ "uappnd,nouchg,nodump,noopaque,uunlnk,nosystem");
/* Test archive_entry_copy_fflags_text_w() */
archive_entry_copy_fflags_text_w(e, L" ,nouappnd, nouchg, dump,uunlnk");
archive_entry_fflags(e, &set, &clear);
diff --git a/libarchive/test/test_read_format_rar5.c b/libarchive/test/test_read_format_rar5.c
index 7f2f32df48c5..0be9c45a5d49 100644
--- a/libarchive/test/test_read_format_rar5.c
+++ b/libarchive/test/test_read_format_rar5.c
@@ -96,7 +96,7 @@ int extract_one(struct archive* a, struct archive_entry* ae, uint32_t crc) {
int ret = 1;
uint32_t computed_crc;
- fsize = archive_entry_size(ae);
+ fsize = (la_ssize_t) archive_entry_size(ae);
buf = malloc(fsize);
if(buf == NULL)
return 1;
@@ -110,13 +110,13 @@ int extract_one(struct archive* a, struct archive_entry* ae, uint32_t crc) {
computed_crc = crc32(0, buf, fsize);
assertEqualInt(computed_crc, crc);
ret = 0;
-
+
fn_exit:
free(buf);
return ret;
}
-DEFINE_TEST(test_read_format_rar5_stored)
+DEFINE_TEST(test_read_format_rar5_stored)
{
const char helloworld_txt[] = "hello libarchive test suite!\n";
la_ssize_t file_size = sizeof(helloworld_txt) - 1;
@@ -143,7 +143,7 @@ DEFINE_TEST(test_read_format_rar5_stored)
DEFINE_TEST(test_read_format_rar5_compressed)
{
const int DATA_SIZE = 1200;
- uint8_t buff[DATA_SIZE];
+ uint8_t buff[1200];
PROLOGUE("test_read_format_rar5_compressed.rar");
@@ -161,7 +161,7 @@ DEFINE_TEST(test_read_format_rar5_compressed)
DEFINE_TEST(test_read_format_rar5_multiple_files)
{
const int DATA_SIZE = 4096;
- uint8_t buff[DATA_SIZE];
+ uint8_t buff[4096];
PROLOGUE("test_read_format_rar5_multiple_files.rar");
@@ -173,7 +173,7 @@ DEFINE_TEST(test_read_format_rar5_multiple_files)
assertEqualInt(DATA_SIZE, archive_entry_size(ae));
assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
assertA(verify_data(buff, 1, DATA_SIZE));
-
+
assertA(0 == archive_read_next_header(a, &ae));
assertEqualString("test2.bin", archive_entry_pathname(ae));
assertEqualInt(DATA_SIZE, archive_entry_size(ae));
@@ -207,7 +207,7 @@ DEFINE_TEST(test_read_format_rar5_multiple_files)
DEFINE_TEST(test_read_format_rar5_multiple_files_solid)
{
const int DATA_SIZE = 4096;
- uint8_t buff[DATA_SIZE];
+ uint8_t buff[4096];
PROLOGUE("test_read_format_rar5_multiple_files_solid.rar");
@@ -216,7 +216,7 @@ DEFINE_TEST(test_read_format_rar5_multiple_files_solid)
assertEqualInt(DATA_SIZE, archive_entry_size(ae));
assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
assertA(verify_data(buff, 1, DATA_SIZE));
-
+
assertA(0 == archive_read_next_header(a, &ae));
assertEqualString("test2.bin", archive_entry_pathname(ae));
assertEqualInt(DATA_SIZE, archive_entry_size(ae));
@@ -309,7 +309,7 @@ DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all_but_second)
DEFINE_TEST(test_read_format_rar5_blake2)
{
const la_ssize_t proper_size = 814;
- uint8_t buf[proper_size];
+ uint8_t buf[814];
PROLOGUE("test_read_format_rar5_blake2.rar");
assertA(0 == archive_read_next_header(a, &ae));
@@ -334,7 +334,7 @@ DEFINE_TEST(test_read_format_rar5_arm_filter)
* test. */
const la_ssize_t proper_size = 90808;
- uint8_t buf[proper_size];
+ uint8_t buf[90808];
PROLOGUE("test_read_format_rar5_arm.rar");
assertA(0 == archive_read_next_header(a, &ae));
@@ -598,7 +598,7 @@ DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_last)
EPILOGUE();
}
-DEFINE_TEST(test_read_format_rar5_solid_skip_all)
+DEFINE_TEST(test_read_format_rar5_solid_skip_all)
{
const char* reffile = "test_read_format_rar5_solid.rar";
@@ -623,7 +623,7 @@ DEFINE_TEST(test_read_format_rar5_solid_skip_all)
EPILOGUE();
}
-DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_first)
+DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_first)
{
const char* reffile = "test_read_format_rar5_solid.rar";
@@ -649,7 +649,7 @@ DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_first)
EPILOGUE();
}
-DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_second)
+DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_second)
{
const char* reffile = "test_read_format_rar5_solid.rar";
diff --git a/libarchive/test/test_read_format_xar.c b/libarchive/test/test_read_format_xar.c
index 4654f8386efb..1c8524520b39 100644
--- a/libarchive/test/test_read_format_xar.c
+++ b/libarchive/test/test_read_format_xar.c
@@ -799,7 +799,7 @@ static void verify(unsigned char *d, size_t s,
static void verifyB(unsigned char *d, size_t s) {
struct archive* a;
struct archive_entry *entry = NULL;
- la_int64_t buf_size;
+ size_t buf_size;
unsigned char *buf;
assert((a = archive_read_new()) != NULL);
@@ -826,20 +826,20 @@ static void verifyB(unsigned char *d, size_t s) {
// f1, content "onetwothree\n", size 12 bytes
assertA(0 == archive_read_next_header(a, &entry));
- buf_size = archive_entry_size(entry);
+ buf_size = (size_t) archive_entry_size(entry);
assertA(buf_size == 12);
buf = (unsigned char*) malloc(buf_size);
assertA(NULL != buf);
- assertA(buf_size == archive_read_data(a, buf, buf_size));
+ assertA(buf_size == (size_t) archive_read_data(a, buf, buf_size));
free(buf);
// f2, content "fourfivesix\n", size 12 bytes
assertA(0 == archive_read_next_header(a, &entry));
- buf_size = archive_entry_size(entry);
+ buf_size = (size_t) archive_entry_size(entry);
assertA(buf_size == 12);
buf = (unsigned char*) malloc(buf_size);
assertA(NULL != buf);
- assertA(buf_size == archive_read_data(a, buf, buf_size));
+ assertA(buf_size == (size_t) archive_read_data(a, buf, buf_size));
free(buf);
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
diff --git a/libarchive/test/test_read_format_zip.c b/libarchive/test/test_read_format_zip.c
index b965299a4f5c..14c5ada81053 100644
--- a/libarchive/test/test_read_format_zip.c
+++ b/libarchive/test/test_read_format_zip.c
@@ -37,7 +37,7 @@ int extract_one(struct archive* a, struct archive_entry* ae, uint32_t crc)
int ret = 1;
uint32_t computed_crc;
- fsize = archive_entry_size(ae);
+ fsize = (la_ssize_t) archive_entry_size(ae);
buf = malloc(fsize);
if(buf == NULL)
return 1;
@@ -759,3 +759,67 @@ DEFINE_TEST(test_read_format_zip_xz_multi_blockread)
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
}
+
+DEFINE_TEST(test_read_format_zip_ppmd8_crash_1)
+{
+ const char *refname = "test_read_format_zip_ppmd8_crash_2.zipx";
+ struct archive *a;
+ struct archive_entry *ae;
+ char buf[64];
+
+ extract_reference_file(refname);
+
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 100));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+
+ /* This file shouldn't be properly decompressed, because it's invalid.
+ * However, unpacker should return an error during unpacking. Without the
+ * proper fix, the unpacker was entering an unlimited loop. */
+ assertEqualIntA(a, ARCHIVE_FATAL, archive_read_data(a, buf, 1));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
+}
+
+DEFINE_TEST(test_read_format_zip_bz2_hang_on_invalid)
+{
+ const char *refname = "test_read_format_zip_bz2_hang.zip";
+ struct archive *a;
+ struct archive_entry *ae;
+ char buf[8];
+
+ extract_reference_file(refname);
+
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+
+ /* The file `refname` is invalid in this case, so this call should fail.
+ * But it shouldn't crash. */
+ assertEqualIntA(a, ARCHIVE_FATAL, archive_read_data(a, buf, 64));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
+}
+
+DEFINE_TEST(test_read_format_zip_ppmd8_crash_2)
+{
+ const char *refname = "test_read_format_zip_ppmd8_crash_2.zipx";
+ struct archive *a;
+ struct archive_entry *ae;
+ char buf[64];
+
+ extract_reference_file(refname);
+
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+
+ /* The file `refname` is invalid in this case, so this call should fail.
+ * But it shouldn't crash. */
+ assertEqualIntA(a, ARCHIVE_FATAL, archive_read_data(a, buf, 64));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
+}
diff --git a/libarchive/test/test_read_format_zip_bz2_hang.zip.uu b/libarchive/test/test_read_format_zip_bz2_hang.zip.uu
new file mode 100644
index 000000000000..5193a77aee33
--- /dev/null
+++ b/libarchive/test/test_read_format_zip_bz2_hang.zip.uu
@@ -0,0 +1,5 @@
+begin 644 test_read_format_zip_bz2_hang.zip
+M4$L#!)LP,#`,,#`P,#`P,#`P,#`P,#`P,#`$`!P`,#`P,#`P"0`P,#`P,#`P
+1,#!U>`L`8(0P,#`P,#`P,#``
+`
+end
diff --git a/libarchive/test/test_read_format_zip_ppmd8_crash_1.zipx.uu b/libarchive/test/test_read_format_zip_ppmd8_crash_1.zipx.uu
new file mode 100644
index 000000000000..fb6050fc086d
--- /dev/null
+++ b/libarchive/test/test_read_format_zip_ppmd8_crash_1.zipx.uu
@@ -0,0 +1,4 @@
+begin 644 test_read_format_zip_ppmd8_crash_1.zipx
+K4$L'"(=02P,$\+N.O&*A>*\+."U``$H`````````@``````#````6(0`````
+`
+end
diff --git a/libarchive/test/test_read_format_zip_ppmd8_crash_2.zipx.uu b/libarchive/test/test_read_format_zip_ppmd8_crash_2.zipx.uu
new file mode 100644
index 000000000000..58de41258665
--- /dev/null
+++ b/libarchive/test/test_read_format_zip_ppmd8_crash_2.zipx.uu
@@ -0,0 +1,4 @@
+begin 644 test_read_format_zip_ppmd8_crash_2.zipx
+L4$L'"(=02P,$\+N.O&*A>*\+.2U`@$H`````````@``````#````````````
+`
+end