| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <set> | 5 #include <set> |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 ASSERT_FALSE(zip::Unzip(path, output_dir)); | 106 ASSERT_FALSE(zip::Unzip(path, output_dir)); |
| 107 FilePath evil_file = output_dir; | 107 FilePath evil_file = output_dir; |
| 108 evil_file = evil_file.AppendASCII( | 108 evil_file = evil_file.AppendASCII( |
| 109 "../levilevilevilevilevilevilevilevilevilevilevilevil"); | 109 "../levilevilevilevilevilevilevilevilevilevilevilevil"); |
| 110 ASSERT_FALSE(file_util::PathExists(evil_file)); | 110 ASSERT_FALSE(file_util::PathExists(evil_file)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 TEST_F(ZipTest, UnzipEvil2) { | 113 TEST_F(ZipTest, UnzipEvil2) { |
| 114 FilePath path; | 114 FilePath path; |
| 115 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); | 115 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); |
| 116 // The zip file contains an evil file with invalid UTF-8 in its file |
| 117 // name. |
| 116 path = path.AppendASCII("zip").AppendASCII("evil_via_invalid_utf8.zip"); | 118 path = path.AppendASCII("zip").AppendASCII("evil_via_invalid_utf8.zip"); |
| 117 // See the comment at UnzipEvil() for why we do this. | 119 // See the comment at UnzipEvil() for why we do this. |
| 118 FilePath output_dir = test_dir_.AppendASCII("out"); | 120 FilePath output_dir = test_dir_.AppendASCII("out"); |
| 119 ASSERT_TRUE(zip::Unzip(path, output_dir)); | 121 // This should fail as it contains an evil file. |
| 122 ASSERT_FALSE(zip::Unzip(path, output_dir)); |
| 120 FilePath evil_file = output_dir; | 123 FilePath evil_file = output_dir; |
| 121 evil_file = evil_file.AppendASCII("../evil.txt"); | 124 evil_file = evil_file.AppendASCII("../evil.txt"); |
| 122 ASSERT_FALSE(file_util::PathExists(evil_file)); | 125 ASSERT_FALSE(file_util::PathExists(evil_file)); |
| 123 } | 126 } |
| 124 | 127 |
| 125 TEST_F(ZipTest, Zip) { | 128 TEST_F(ZipTest, Zip) { |
| 126 FilePath src_dir; | 129 FilePath src_dir; |
| 127 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &src_dir)); | 130 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &src_dir)); |
| 128 src_dir = src_dir.AppendASCII("zip").AppendASCII("test"); | 131 src_dir = src_dir.AppendASCII("zip").AppendASCII("test"); |
| 129 | 132 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 142 | 145 |
| 143 ScopedTempDir temp_dir; | 146 ScopedTempDir temp_dir; |
| 144 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 147 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 145 FilePath zip_file = temp_dir.path().AppendASCII("out.zip"); | 148 FilePath zip_file = temp_dir.path().AppendASCII("out.zip"); |
| 146 | 149 |
| 147 EXPECT_TRUE(zip::Zip(src_dir, zip_file, false)); | 150 EXPECT_TRUE(zip::Zip(src_dir, zip_file, false)); |
| 148 TestUnzipFile(zip_file, false); | 151 TestUnzipFile(zip_file, false); |
| 149 } | 152 } |
| 150 | 153 |
| 151 } // namespace | 154 } // namespace |
| OLD | NEW |