summaryrefslogtreecommitdiff
path: root/libziparchive
diff options
context:
space:
mode:
authorMykola Kondratenko <mykola.kondratenko@sonymobile.com>2014-09-08 12:46:37 +0200
committerNarayan Kamath <narayan@google.com>2015-03-19 09:28:41 +0000
commit50afc159b3bba06cd02648b1e287ba06d4fac059 (patch)
tree2e4191bc43a861ae72e7c4c8d072972c8884f164 /libziparchive
parentee2e362f8be4cbf68bb38fa1916a1f395677c593 (diff)
libziparchive: fix issue with a directory with one file
libziparchive fails to iterate some bootanimation archives reporting invalid offset error. This is caused by failure to process a directory with one file (when name_offset + file_name_length == cd_offset). Change-Id: I2733e7f782c14a6fadd5491bb94318ac968df206
Diffstat (limited to 'libziparchive')
-rw-r--r--libziparchive/testdata/declaredlength.zipbin0 -> 886 bytes
-rw-r--r--libziparchive/zip_archive.cc2
-rw-r--r--libziparchive/zip_archive_test.cc16
3 files changed, 17 insertions, 1 deletions
diff --git a/libziparchive/testdata/declaredlength.zip b/libziparchive/testdata/declaredlength.zip
new file mode 100644
index 000000000..773380c45
--- /dev/null
+++ b/libziparchive/testdata/declaredlength.zip
Binary files differ
diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc
index e820f2a5f..6475649d5 100644
--- a/libziparchive/zip_archive.cc
+++ b/libziparchive/zip_archive.cc
@@ -824,7 +824,7 @@ static int32_t FindEntry(const ZipArchive* archive, const int ent,
// name in the central directory.
if (lfh->file_name_length == nameLen) {
const off64_t name_offset = local_header_offset + sizeof(LocalFileHeader);
- if (name_offset + lfh->file_name_length >= cd_offset) {
+ if (name_offset + lfh->file_name_length > cd_offset) {
ALOGW("Zip: Invalid declared length");
return kInvalidOffset;
}
diff --git a/libziparchive/zip_archive_test.cc b/libziparchive/zip_archive_test.cc
index c8dafa9f6..64faa6de2 100644
--- a/libziparchive/zip_archive_test.cc
+++ b/libziparchive/zip_archive_test.cc
@@ -171,6 +171,22 @@ TEST(ziparchive, FindEntry) {
CloseArchive(handle);
}
+TEST(ziparchive, TestInvalidDeclaredLength) {
+ ZipArchiveHandle handle;
+ ASSERT_EQ(0, OpenArchiveWrapper("declaredlength.zip", &handle));
+
+ void* iteration_cookie;
+ ASSERT_EQ(0, StartIteration(handle, &iteration_cookie, NULL));
+
+ ZipEntryName name;
+ ZipEntry data;
+
+ ASSERT_EQ(Next(iteration_cookie, &data, &name), 0);
+ ASSERT_EQ(Next(iteration_cookie, &data, &name), 0);
+
+ CloseArchive(handle);
+}
+
TEST(ziparchive, ExtractToMemory) {
ZipArchiveHandle handle;
ASSERT_EQ(0, OpenArchiveWrapper(kValidZip, &handle));