@@ -1438,7 +1438,15 @@ TEST(ZlibTest, ZipUnicodePathExtraSizeFilenameOverflow) {
14381438 base::FilePath zip_file = TestDataDir ().AppendASCII (" unicode_path_extra_overflow.zip" );
14391439 unzFile uzf = unzOpen (zip_file.AsUTF8Unsafe ().c_str ());
14401440 ASSERT_NE (uzf, nullptr );
1441- EXPECT_EQ (unzGoToFirstFile (uzf), UNZ_ERRNO );
1441+
1442+ char name[100 ];
1443+ unz_file_info file_info;
1444+ ASSERT_EQ (unzGoToFirstFile (uzf), UNZ_OK );
1445+ // The bad Unicode Path Extra Field should be ignored, and we get the regular
1446+ // filename.
1447+ ASSERT_EQ (unzGetCurrentFileInfo (uzf, &file_info, name, sizeof (name), nullptr ,
1448+ 0 , nullptr , 0 ), UNZ_OK );
1449+ ASSERT_EQ (std::string (name), " \xc8\xfe \xc8\xfe\xc8\xfe .txt" );
14421450 EXPECT_EQ (unzClose (uzf), UNZ_OK );
14431451}
14441452
@@ -1482,6 +1490,34 @@ TEST(ZlibTest, ZipUnicodePathExtra) {
14821490 EXPECT_EQ (unzClose (uzf), UNZ_OK );
14831491}
14841492
1493+ TEST (ZlibTest, ShortZipUnicodePathExtra) {
1494+ base::FilePath zip_file = TestDataDir ().AppendASCII (" short_unicode_path_extra.zip" );
1495+ unzFile uzf = unzOpen (zip_file.AsUTF8Unsafe ().c_str ());
1496+ ASSERT_NE (uzf, nullptr );
1497+
1498+ char name[100 ];
1499+ unz_file_info file_info;
1500+
1501+ ASSERT_EQ (unzGoToFirstFile (uzf), UNZ_OK );
1502+ ASSERT_EQ (unzGetCurrentFileInfo (uzf, &file_info, name, sizeof (name), nullptr ,
1503+ 0 , nullptr , 0 ), UNZ_OK );
1504+ ASSERT_EQ (std::string (name), " receipt.txt" );
1505+
1506+ // The "decoy.dat" entry has an invalid (too short) Unicode Path Extra Field.
1507+ // Ignore the extra field rather than erroring out.
1508+ ASSERT_EQ (unzGoToNextFile (uzf), UNZ_OK );
1509+ ASSERT_EQ (unzGetCurrentFileInfo (uzf, &file_info, name, sizeof (name), nullptr ,
1510+ 0 , nullptr , 0 ), UNZ_OK );
1511+ ASSERT_EQ (std::string (name), " decoy.dat" );
1512+
1513+ ASSERT_EQ (unzGoToNextFile (uzf), UNZ_OK );
1514+ ASSERT_EQ (unzGetCurrentFileInfo (uzf, &file_info, name, sizeof (name), nullptr ,
1515+ 0 , nullptr , 0 ), UNZ_OK );
1516+ ASSERT_EQ (std::string (name), " malware.exe" );
1517+
1518+ EXPECT_EQ (unzClose (uzf), UNZ_OK );
1519+ }
1520+
14851521TEST (ZlibTest, ZipEncryptionFlagMismatch) {
14861522 // Test archive created with info-zip:
14871523 // $ echo -n a > a && zip -P a -k a.zip a
0 commit comments