summaryrefslogtreecommitdiff
path: root/google/zip_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'google/zip_unittest.cc')
-rw-r--r--google/zip_unittest.cc257
1 files changed, 177 insertions, 80 deletions
diff --git a/google/zip_unittest.cc b/google/zip_unittest.cc
index 8fbec32..b639e8e 100644
--- a/google/zip_unittest.cc
+++ b/google/zip_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -20,6 +20,7 @@
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/path_service.h"
+#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
@@ -38,6 +39,7 @@
namespace {
using testing::UnorderedElementsAre;
+using testing::UnorderedElementsAreArray;
std::vector<std::string> GetRelativePaths(const base::FilePath& dir,
base::FileEnumerator::FileType type) {
@@ -46,7 +48,7 @@ std::vector<std::string> GetRelativePaths(const base::FilePath& dir,
for (base::FilePath path = files.Next(); !path.empty(); path = files.Next()) {
base::FilePath relative;
EXPECT_TRUE(dir.AppendRelativePath(path, &relative));
- got_paths.push_back(relative.AsUTF8Unsafe());
+ got_paths.push_back(relative.NormalizePathSeparatorsTo('/').AsUTF8Unsafe());
}
EXPECT_EQ(base::File::FILE_OK, files.GetError());
@@ -401,11 +403,9 @@ TEST_F(ZipTest, UnzipEvil) {
// won't create a persistent file outside test_dir_ in case of a
// failure.
base::FilePath output_dir = test_dir_.AppendASCII("out");
- ASSERT_FALSE(zip::Unzip(path, output_dir));
- base::FilePath evil_file = output_dir;
- evil_file = evil_file.AppendASCII(
- "../levilevilevilevilevilevilevilevilevilevilevilevil");
- ASSERT_FALSE(base::PathExists(evil_file));
+ EXPECT_TRUE(zip::Unzip(path, output_dir));
+ EXPECT_TRUE(base::PathExists(output_dir.AppendASCII(
+ "UP/levilevilevilevilevilevilevilevilevilevilevilevil")));
}
TEST_F(ZipTest, UnzipEvil2) {
@@ -416,7 +416,7 @@ TEST_F(ZipTest, UnzipEvil2) {
base::FilePath output_dir = test_dir_.AppendASCII("out");
ASSERT_TRUE(zip::Unzip(path, output_dir));
ASSERT_TRUE(base::PathExists(
- output_dir.Append(base::FilePath::FromUTF8Unsafe(".�.\\evil.txt"))));
+ output_dir.Append(base::FilePath::FromUTF8Unsafe(".�.�evil.txt"))));
ASSERT_FALSE(base::PathExists(output_dir.AppendASCII("../evil.txt")));
}
@@ -588,37 +588,84 @@ TEST_F(ZipTest, UnzipCannotCreateParentDir) {
EXPECT_EQ("First file", contents);
}
+// TODO(crbug.com/1311140) Detect and rename reserved file names on Windows.
TEST_F(ZipTest, UnzipWindowsSpecialNames) {
- EXPECT_TRUE(zip::Unzip(
- GetDataDirectory().AppendASCII("Windows Special Names.zip"), test_dir_));
+ EXPECT_TRUE(
+ zip::Unzip(GetDataDirectory().AppendASCII("Windows Special Names.zip"),
+ test_dir_, {.continue_on_error = true}));
- std::string contents;
- EXPECT_TRUE(base::ReadFileToString(test_dir_.AppendASCII("Last"), &contents));
- EXPECT_EQ("Last file", contents);
+ std::unordered_set<std::string> want_paths = {
+ "First",
+ "Last",
+ "CLOCK$",
+ " NUL.txt",
+#ifndef OS_WIN
+ "NUL",
+ "NUL ",
+ "NUL.",
+ "NUL .",
+ "NUL.txt",
+ "NUL.tar.gz",
+ "NUL..txt",
+ "NUL...txt",
+ "NUL .txt",
+ "NUL .txt",
+ "NUL ..txt",
+#ifndef OS_MAC
+ "Nul.txt",
+#endif
+ "nul.very long extension",
+ "a/NUL",
+ "CON",
+ "PRN",
+ "AUX",
+ "COM1",
+ "COM2",
+ "COM3",
+ "COM4",
+ "COM5",
+ "COM6",
+ "COM7",
+ "COM8",
+ "COM9",
+ "LPT1",
+ "LPT2",
+ "LPT3",
+ "LPT4",
+ "LPT5",
+ "LPT6",
+ "LPT7",
+ "LPT8",
+ "LPT9",
+#endif
+ };
+
+ const std::vector<std::string> got_paths =
+ GetRelativePaths(test_dir_, base::FileEnumerator::FileType::FILES);
+
+ for (const std::string& path : got_paths) {
+ const bool ok = want_paths.erase(path);
#ifdef OS_WIN
- // On Windows, the NUL* files are simply missing. No error is reported. Not
- // even an error message in the logs.
- EXPECT_THAT(
- GetRelativePaths(test_dir_, base::FileEnumerator::FileType::FILES),
- UnorderedElementsAre("First", "Last"));
+ if (!ok) {
+ // See crbug.com/1313991: Different versions of Windows treat these
+ // filenames differently. No hard error here if there is an unexpected
+ // file.
+ LOG(WARNING) << "Found unexpected file: " << std::quoted(path);
+ continue;
+ }
#else
- EXPECT_THAT(
- GetRelativePaths(test_dir_, base::FileEnumerator::FileType::FILES),
- UnorderedElementsAre("First", "Last", "NUL", "Nul.txt",
- "nul.very long extension"));
-
- EXPECT_TRUE(base::ReadFileToString(test_dir_.AppendASCII("NUL"), &contents));
- EXPECT_EQ("This is: NUL", contents);
+ EXPECT_TRUE(ok) << "Found unexpected file: " << std::quoted(path);
+#endif
- EXPECT_TRUE(
- base::ReadFileToString(test_dir_.AppendASCII("Nul.txt"), &contents));
- EXPECT_EQ("This is: Nul.txt", contents);
+ std::string contents;
+ EXPECT_TRUE(base::ReadFileToString(test_dir_.AppendASCII(path), &contents));
+ EXPECT_EQ(base::StrCat({"This is: ", path}), contents);
+ }
- EXPECT_TRUE(base::ReadFileToString(
- test_dir_.AppendASCII("nul.very long extension"), &contents));
- EXPECT_EQ("This is: nul.very long extension", contents);
-#endif
+ for (const std::string& path : want_paths) {
+ EXPECT_TRUE(false) << "Cannot find expected file: " << std::quoted(path);
+ }
}
TEST_F(ZipTest, UnzipDifferentCases) {
@@ -695,45 +742,49 @@ TEST_F(ZipTest, UnzipMixedPaths) {
std::unordered_set<std::string> want_paths = {
#ifdef OS_WIN
- "Dot", //
- "Space→", //
- "a\\b", //
- "u\\v\\w\\x\\y\\z", //
- "←Backslash2", //
+ "Dot", //
+ "Space→", //
#else
- " ", // Invalid on Windows
- "Angle <>", // Invalid on Windows
- "Backslash1→\\", //
- "Backspace \x08", // Invalid on Windows
- "Bell \a", // Invalid on Windows
- "C:", // Invalid on Windows
- "C:\\", // Absolute path on Windows
- "C:\\Temp", // Absolute path on Windows
- "C:\\Temp\\", // Absolute path on Windows
- "C:\\Temp\\File", // Absolute path on Windows
- "Carriage Return \r", // Invalid on Windows
- "Colon :", // Invalid on Windows
- "Dot .", // Becomes "Dot" on Windows
- "Double quote \"", // Invalid on Windows
- "Escape \x1B", // Invalid on Windows
- "Line Feed \n", // Invalid on Windows
+ " ", //
+ "AUX", // Disappears on Windows
+ "COM1", // Disappears on Windows
+ "COM2", // Disappears on Windows
+ "COM3", // Disappears on Windows
+ "COM4", // Disappears on Windows
+ "COM5", // Disappears on Windows
+ "COM6", // Disappears on Windows
+ "COM7", // Disappears on Windows
+ "COM8", // Disappears on Windows
+ "COM9", // Disappears on Windows
+ "CON", // Disappears on Windows
+ "Dot .", //
+ "LPT1", // Disappears on Windows
+ "LPT2", // Disappears on Windows
+ "LPT3", // Disappears on Windows
+ "LPT4", // Disappears on Windows
+ "LPT5", // Disappears on Windows
+ "LPT6", // Disappears on Windows
+ "LPT7", // Disappears on Windows
+ "LPT8", // Disappears on Windows
+ "LPT9", // Disappears on Windows
+ "NUL ..txt", // Disappears on Windows
+ "NUL .txt", // Disappears on Windows
+ "NUL ", // Disappears on Windows
+ "NUL .", // Disappears on Windows
"NUL .txt", // Disappears on Windows
"NUL", // Disappears on Windows
+ "NUL.", // Disappears on Windows
+ "NUL...txt", // Disappears on Windows
"NUL..txt", // Disappears on Windows
"NUL.tar.gz", // Disappears on Windows
"NUL.txt", // Disappears on Windows
- "Pipe |", // Invalid on Windows
- "Question ?", // Invalid on Windows
- "Space→ ", // Becomes "Space→" on Windows
- "Star *", // Invalid on Windows
- "Tab \t", // Invalid on Windows
- "\\\\server\\share\\file", // Absolute path on Windows
- "\\←Backslash2", // Becomes "←Backslash2" on Windows
- "a/b", //
- "u/v/w/x/y/z", //
+ "PRN", // Disappears on Windows
+ "Space→ ", //
+ "c/NUL", // Disappears on Windows
+ "nul.very long extension", // Disappears on Windows
#ifndef OS_MAC
- "CASE", //
- "Case", //
+ "CASE", // Conflicts with "Case"
+ "case", // Conflicts with "Case"
#endif
#endif
" NUL.txt", //
@@ -741,46 +792,82 @@ TEST_F(ZipTest, UnzipMixedPaths) {
"$HOME", //
"%TMP", //
"-", //
- "...Tree", //
+ "...Three", //
"..Two", //
".One", //
"Ampersand &", //
+ "Angle ��", //
"At @", //
- "Backslash3→\\←Backslash4", //
+ "Backslash1→�", //
+ "Backslash3→�←Backslash4", //
+ "Backspace �", //
"Backtick `", //
+ "Bell �", //
+ "CLOCK$", //
"Caret ^", //
+ "Carriage Return �", //
+ "Case", //
+ "Colon �", //
"Comma ,", //
"Curly {}", //
+ "C�", //
+ "C��", //
+ "C��Temp", //
+ "C��Temp�", //
+ "C��Temp�File", //
"Dash -", //
"Delete \x7F", //
"Dollar $", //
+ "Double quote �", //
"Equal =", //
+ "Escape �", //
"Euro €", //
"Exclamation !", //
"FileOrDir", //
"First", //
"Hash #", //
"Last", //
+ "Line Feed �", //
"Percent %", //
+ "Pipe �", //
"Plus +", //
+ "Question �", //
"Quote '", //
+ "ROOT/At The Top", //
+ "ROOT/UP/Over The Top", //
+ "ROOT/dev/null", //
"Round ()", //
"Semicolon ;", //
"Smile \U0001F642", //
"Square []", //
+ "Star �", //
"String Terminator \u009C", //
+ "Tab �", //
"Tilde ~", //
+ "UP/One Level Up", //
+ "UP/UP/Two Levels Up", //
"Underscore _", //
- "case", //
+ "a/DOT/b", //
+ "a/UP/b", //
+ "u/v/w/x/y/z", //
"~", //
+ "�←Backslash2", //
+ "��server�share�file", //
};
const std::vector<std::string> got_paths =
GetRelativePaths(test_dir_, base::FileEnumerator::FileType::FILES);
for (const std::string& path : got_paths) {
- EXPECT_TRUE(want_paths.erase(path))
- << "Found unexpected file: " << std::quoted(path);
+ const bool ok = want_paths.erase(path);
+#ifdef OS_WIN
+ // See crbug.com/1313991: Different versions of Windows treat reserved
+ // Windows filenames differently. No hard error here if there is an
+ // unexpected file.
+ LOG_IF(WARNING, !ok) << "Found unexpected file: " << std::quoted(path);
+#else
+ EXPECT_TRUE(ok) << "Found unexpected file: " << std::quoted(path);
+#endif
}
for (const std::string& path : want_paths) {
@@ -789,14 +876,24 @@ TEST_F(ZipTest, UnzipMixedPaths) {
EXPECT_THAT(
GetRelativePaths(test_dir_, base::FileEnumerator::FileType::DIRECTORIES),
- UnorderedElementsAre(
-#ifdef OS_WIN
- "Backslash3→", "Empty", "a", "u", "u\\v", "u\\v\\w", "u\\v\\w\\x",
- "u\\v\\w\\x\\y"
-#else
- "Empty", "a", "u", "u/v", "u/v/w", "u/v/w/x", "u/v/w/x/y"
-#endif
- ));
+ UnorderedElementsAreArray({
+ "Empty",
+ "ROOT",
+ "ROOT/Empty",
+ "ROOT/UP",
+ "ROOT/dev",
+ "UP",
+ "UP/UP",
+ "a",
+ "a/DOT",
+ "a/UP",
+ "c",
+ "u",
+ "u/v",
+ "u/v/w",
+ "u/v/w/x",
+ "u/v/w/x/y",
+ }));
}
TEST_F(ZipTest, UnzipWithDelegates) {
@@ -897,7 +994,7 @@ TEST_F(ZipTest, UnzipSjisAsUtf8) {
std::string contents;
ASSERT_TRUE(base::ReadFileToString(
- dir.Append(base::FilePath::FromUTF8Unsafe("SJIS_835C_�\\.txt")),
+ dir.Append(base::FilePath::FromUTF8Unsafe("SJIS_835C_��.txt")),
&contents));
EXPECT_EQ(
"This file's name contains 0x5c (backslash) as the 2nd byte of Japanese "
@@ -1261,10 +1358,10 @@ TEST_F(ZipTest, NestedZip) {
// performing this test (android-asan, android-11-x86-rel,
// android-marshmallow-x86-rel-non-cq).
// Some Mac, Linux and Debug (dbg) bots tend to time out when performing this
-// test (crbug.com/1299736, crbug.com/1300448).
+// test (crbug.com/1299736, crbug.com/1300448, crbug.com/1369958).
#if defined(THREAD_SANITIZER) || BUILDFLAG(IS_FUCHSIA) || \
BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || \
- BUILDFLAG(IS_CHROMEOS_LACROS) || !defined(NDEBUG)
+ BUILDFLAG(IS_CHROMEOS) || !defined(NDEBUG)
TEST_F(ZipTest, DISABLED_BigFile) {
#else
TEST_F(ZipTest, BigFile) {