summaryrefslogtreecommitdiffstats
path: root/chrome/common/zip_unittest.cc
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-01 23:28:30 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-01 23:28:30 +0000
commiteb52217be8ad4d8380271dcee9e7ffc289736b42 (patch)
treefc1f816516bef9f6157ad7cc28a4a33f45b04527 /chrome/common/zip_unittest.cc
parent58b0fd6743c7ea11057eefe7b63ace3079ff2cc4 (diff)
downloadchromium_src-eb52217be8ad4d8380271dcee9e7ffc289736b42.zip
chromium_src-eb52217be8ad4d8380271dcee9e7ffc289736b42.tar.gz
chromium_src-eb52217be8ad4d8380271dcee9e7ffc289736b42.tar.bz2
Fix subtle flakiness from ZipTest.
UnzipEvil and UnzipEvil2 check that we don't extract files containing .. in their file names. These tests failed if we had "levilevilevilevilevilevilevilevilevilevilevilevil" and "evil.txt" in /tmp on Linux, as we were checking the existence of these files from a temporary directory like /tmp/.org.chromium.Chromium.aXW1Gx. We should create a directory one level deeper to fix the subtle issue. TEST=touch /tmp/levilevilevilevilevilevilevilevilevilevilevilevil /tmp/evil.txt; out/Release/unit_tests --gtest_filter=ZipTest.* BUG=chromium-os:22351 Review URL: http://codereview.chromium.org/8437016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108195 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/zip_unittest.cc')
-rw-r--r--chrome/common/zip_unittest.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/chrome/common/zip_unittest.cc b/chrome/common/zip_unittest.cc
index dfffd09..1108720 100644
--- a/chrome/common/zip_unittest.cc
+++ b/chrome/common/zip_unittest.cc
@@ -99,8 +99,12 @@ TEST_F(ZipTest, UnzipEvil) {
FilePath path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
path = path.AppendASCII("zip").AppendASCII("evil.zip");
- ASSERT_FALSE(zip::Unzip(path, test_dir_));
- FilePath evil_file = test_dir_;
+ // Unzip the zip file into a sub directory of test_dir_ so evil.zip
+ // won't create a persistent file outside test_dir_ in case of a
+ // failure.
+ FilePath output_dir = test_dir_.AppendASCII("out");
+ ASSERT_FALSE(zip::Unzip(path, output_dir));
+ FilePath evil_file = output_dir;
evil_file = evil_file.AppendASCII(
"../levilevilevilevilevilevilevilevilevilevilevilevil");
ASSERT_FALSE(file_util::PathExists(evil_file));
@@ -110,8 +114,10 @@ TEST_F(ZipTest, UnzipEvil2) {
FilePath path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
path = path.AppendASCII("zip").AppendASCII("evil_via_invalid_utf8.zip");
- ASSERT_TRUE(zip::Unzip(path, test_dir_));
- FilePath evil_file = test_dir_;
+ // See the comment at UnzipEvil() for why we do this.
+ FilePath output_dir = test_dir_.AppendASCII("out");
+ ASSERT_TRUE(zip::Unzip(path, output_dir));
+ FilePath evil_file = output_dir;
evil_file = evil_file.AppendASCII("../evil.txt");
ASSERT_FALSE(file_util::PathExists(evil_file));
}