| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1439,6 +1439,8 @@ local int unz64local_CheckCurrentFileCoherencyHeader(unz64_s* s, uInt* piSizeVar | |||
| 1439 | 1439 | */ | |
| 1440 | 1440 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) | |
| 1441 | 1441 | err=UNZ_ERRNO; | |
| 1442 | + else if ((err==UNZ_OK) && ((uFlags & 1) != (s->cur_file_info.flag & 1))) | ||
| 1443 | + err=UNZ_BADZIPFILE; /* LFH/CD encryption flag mismatch */ | ||
| 1442 | 1444 | ||
| 1443 | 1445 | if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) | |
| 1444 | 1446 | err=UNZ_ERRNO; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1424,6 +1424,29 @@ TEST(ZlibTest, ZipUnicodePathExtra) { | |||
| 1424 | 1424 | EXPECT_EQ(unzClose(uzf), UNZ_OK); | |
| 1425 | 1425 | } | |
| 1426 | 1426 | ||
| 1427 | + TEST(ZlibTest, ZipEncryptionFlagMismatch) { | ||
| 1428 | + // Test archive created with info-zip: | ||
| 1429 | + // $ echo -n a > a && zip -P a -k a.zip a | ||
| 1430 | + // and then hex-edited to drop the encrypted flag from the central directory. | ||
| 1431 | + base::FilePath zip_file = TestDataDir().AppendASCII("enc_flag_mismatch.zip"); | ||
| 1432 | + | ||
| 1433 | + unzFile uzf = unzOpen(zip_file.AsUTF8Unsafe().c_str()); | ||
| 1434 | + ASSERT_NE(uzf, nullptr); | ||
| 1435 | + | ||
| 1436 | + char name[100]; | ||
| 1437 | + unz_file_info file_info; | ||
| 1438 | + | ||
| 1439 | + ASSERT_EQ(unzGoToFirstFile(uzf), UNZ_OK); | ||
| 1440 | + ASSERT_EQ(unzGetCurrentFileInfo(uzf, &file_info, name, sizeof(name), | ||
| 1441 | + nullptr, 0, nullptr, 0), UNZ_OK); | ||
| 1442 | + ASSERT_EQ(std::string(name), "A"); | ||
| 1443 | + | ||
| 1444 | + // minizip should reject the member due to lfh/cd encrypted flag mismatch. | ||
| 1445 | + EXPECT_EQ(unzOpenCurrentFilePassword(uzf, "a"), UNZ_BADZIPFILE); | ||
| 1446 | + | ||
| 1447 | + EXPECT_EQ(unzClose(uzf), UNZ_OK); | ||
| 1448 | + } | ||
| 1449 | + | ||
| 1427 | 1450 | TEST(ZlibTest, Crbug500521311) { | |
| 1428 | 1451 | base::FilePath zip_file = TestDataDir().AppendASCII("bug500521311.zip"); | |
| 1429 | 1452 | unzFile uzf = unzOpen(zip_file.AsUTF8Unsafe().c_str()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,7 @@ test/data/bug500521311.zip | |||
| 19 | 19 | test/data/create_symlink_test_zips.py | |
| 20 | 20 | test/data/create_test_zip.sh | |
| 21 | 21 | test/data/empty.zip | |
| 22 | + test/data/enc_flag_mismatch.zip | ||
| 22 | 23 | test/data/evil.zip | |
| 23 | 24 | test/data/evil_via_absolute_file_name.zip | |
| 24 | 25 | test/data/evil_via_invalid_utf8.zip | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -558,6 +558,24 @@ TEST_F(ZipReaderTest, EncryptedFile_RightPassword) { | |||
| 558 | 558 | EXPECT_TRUE(reader.ok()); | |
| 559 | 559 | } | |
| 560 | 560 | ||
| 561 | + // An entry whose local file header has the "encrypted" general-purpose flag | ||
| 562 | + // bit set while the central directory does not should be rejected. | ||
| 563 | + TEST_F(ZipReaderTest, MismatchedEncryptionFlag) { | ||
| 564 | + ZipReader reader; | ||
| 565 | + ASSERT_TRUE(reader.Open(data_dir_.AppendASCII("enc_flag_mismatch.zip"))); | ||
| 566 | + | ||
| 567 | + const ZipReader::Entry* entry = reader.Next(); | ||
| 568 | + ASSERT_TRUE(entry); | ||
| 569 | + EXPECT_EQ(base::FilePath::FromASCII("A"), entry->path); | ||
| 570 | + EXPECT_FALSE(entry->is_directory); | ||
| 571 | + std::string contents = "dummy"; | ||
| 572 | + EXPECT_FALSE(reader.ExtractCurrentEntryToString(&contents)); | ||
| 573 | + EXPECT_EQ("", contents); | ||
| 574 | + | ||
| 575 | + EXPECT_FALSE(reader.Next()); | ||
| 576 | + EXPECT_TRUE(reader.ok()); | ||
| 577 | + } | ||
| 578 | + | ||
| 561 | 579 | // Verifies that the ZipReader class can extract a file from a zip archive | |
| 562 | 580 | // stored in memory. This test opens a zip archive in a std::string object, | |
| 563 | 581 | // extracts its content, and verifies the content is the same as the expected | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,3 +26,31 @@ index 82275d6c1775d..c8a01b23efd42 100644 | |||
| 26 | 26 | s->encrypted=1; | |
| 27 | 27 | } | |
| 28 | 28 | # endif | |
| 29 | + | ||
| 30 | + commit 874ed6b46a4f75407829e510db77cc673a4c86e7 | ||
| 31 | + Author: Hans Wennborg <hans@chromium.org> | ||
| 32 | + Date: Mon Jun 15 11:33:46 2026 +0200 | ||
| 33 | + | ||
| 34 | + Check LFH / CD encryption flag consistency | ||
| 35 | + | ||
| 36 | + unz64local_CheckCurrentFileCoherencyHeader performs various consistency | ||
| 37 | + checks on the values in the Local File Header and Central Directory. | ||
| 38 | + Make it check the encryption flag as well. | ||
| 39 | + | ||
| 40 | + Bug: 514461031 | ||
| 41 | + Change-Id: Ifaf8620c6e0c345118712bce6e1206bbb83b3a2d | ||
| 42 | + Reviewed-on: https://chromium-review.googlesource.com/7942389 | ||
| 43 | + | ||
| 44 | + diff --git a/third_party/zlib/contrib/minizip/unzip.c b/third_party/zlib/contrib/minizip/unzip.c | ||
| 45 | + index 0264f7ac570f7..4eb0de302cfdf 100644 | ||
| 46 | + --- a/third_party/zlib/contrib/minizip/unzip.c | ||
| 47 | + +++ b/third_party/zlib/contrib/minizip/unzip.c | ||
| 48 | + @@ -1439,6 +1439,8 @@ local int unz64local_CheckCurrentFileCoherencyHeader(unz64_s* s, uInt* piSizeVar | ||
| 49 | + */ | ||
| 50 | + if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) | ||
| 51 | + err=UNZ_ERRNO; | ||
| 52 | + + else if ((err==UNZ_OK) && ((uFlags & 1) != (s->cur_file_info.flag & 1))) | ||
| 53 | + + err=UNZ_BADZIPFILE; /* LFH/CD encryption flag mismatch */ | ||
| 54 | + | ||
| 55 | + if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) | ||
| 56 | + err=UNZ_ERRNO; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,5 +2,5 @@ | |||
| 2 | 2 | // Refer to tools/dep_updaters/update-zlib.sh | |
| 3 | 3 | #ifndef SRC_ZLIB_VERSION_H_ | |
| 4 | 4 | #define SRC_ZLIB_VERSION_H_ | |
| 5 | - #define ZLIB_VERSION "1.3.2.1-motley-3246f1b" | ||
| 5 | + #define ZLIB_VERSION "1.3.2.1-motley-8b3aa8a" | ||
| 6 | 6 | #endif // SRC_ZLIB_VERSION_H_ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments