aboutsummaryrefslogtreecommitdiffstats
path: root/libarchive/test/test_read_format_zip.c
diff options
context:
space:
mode:
Diffstat (limited to 'libarchive/test/test_read_format_zip.c')
-rw-r--r--libarchive/test/test_read_format_zip.c66
1 files changed, 65 insertions, 1 deletions
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));
+}