Merge "libziparchive: fix issue with a directory with one file"

This commit is contained in:
Narayan Kamath 2015-03-19 09:29:08 +00:00 committed by Gerrit Code Review
commit b054582b90
3 changed files with 17 additions and 1 deletions

Binary file not shown.

View File

@ -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;
}

View File

@ -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));