Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Side by Side Diff: third_party/zlib/google/zip_unittest.cc

Issue 222243003: Fixed uncompressing files with wrong uncompressed size set. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/zlib/google/zip_reader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
11 #include "base/files/file_enumerator.h" 11 #include "base/files/file_enumerator.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/platform_test.h" 18 #include "testing/platform_test.h"
18 #include "third_party/zlib/google/zip.h" 19 #include "third_party/zlib/google/zip.h"
19 #include "third_party/zlib/google/zip_reader.h" 20 #include "third_party/zlib/google/zip_reader.h"
20 21
21 namespace { 22 namespace {
22 23
23 // Make the test a PlatformTest to setup autorelease pools properly on Mac. 24 // Make the test a PlatformTest to setup autorelease pools properly on Mac.
24 class ZipTest : public PlatformTest { 25 class ZipTest : public PlatformTest {
25 protected: 26 protected:
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 EXPECT_EQ(zip_file_list_.size(), static_cast<size_t>(reader.num_entries())); 296 EXPECT_EQ(zip_file_list_.size(), static_cast<size_t>(reader.num_entries()));
296 for (size_t i = 0; i < zip_file_list_.size(); ++i) { 297 for (size_t i = 0; i < zip_file_list_.size(); ++i) {
297 EXPECT_TRUE(reader.LocateAndOpenEntry(zip_file_list_[i])); 298 EXPECT_TRUE(reader.LocateAndOpenEntry(zip_file_list_[i]));
298 // Check the path in the entry just in case. 299 // Check the path in the entry just in case.
299 const zip::ZipReader::EntryInfo* entry_info = reader.current_entry_info(); 300 const zip::ZipReader::EntryInfo* entry_info = reader.current_entry_info();
300 EXPECT_EQ(entry_info->file_path(), zip_file_list_[i]); 301 EXPECT_EQ(entry_info->file_path(), zip_file_list_[i]);
301 } 302 }
302 } 303 }
303 #endif // defined(OS_POSIX) 304 #endif // defined(OS_POSIX)
304 305
306 TEST_F(ZipTest, UnzipFilesWithIncorrectSize) {
307 base::FilePath test_data_folder;
308 ASSERT_TRUE(GetTestDataDirectory(&test_data_folder));
309
310 // test_mismatch_size.zip contains files with names from 0.txt to 7.txt with
311 // sizes from 0 to 7 bytes respectively, but the metadata in the zip file says
312 // the uncompressed size is 3 bytes. The ZipReader and minizip code needs to
313 // be clever enough to get all the data out.
314 base::FilePath test_zip_file =
315 test_data_folder.AppendASCII("test_mismatch_size.zip");
316
317 base::ScopedTempDir scoped_temp_dir;
318 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir());
319 const base::FilePath& temp_dir = scoped_temp_dir.path();
320
321 ASSERT_TRUE(zip::Unzip(test_zip_file, temp_dir));
322
323 EXPECT_TRUE(base::DirectoryExists(temp_dir.AppendASCII("d")));
324
325 for (int i = 0; i < 8; i++) {
326 SCOPED_TRACE(base::StringPrintf("<loop:%d>", static_cast<int>(i)));
agl 2014/04/03 14:34:56 |i| is an int, but you're static_casting it to int
satorux1 2014/04/30 00:18:19 Yes. Please remove static_cast from here and elsew
João Eiras 2014/05/07 12:03:51 done
327 base::FilePath file_path = temp_dir.AppendASCII(
328 base::StringPrintf(FILE_PATH_LITERAL("%d.txt"), static_cast<int>(i)));
agl 2014/04/03 14:34:56 I don't think you want FILE_PATH_LITERAL here.
satorux1 2014/04/30 00:18:19 ditto. please address agl's comment.
João Eiras 2014/05/07 12:03:51 done
329 int64 file_size = -1;
330 EXPECT_TRUE(base::GetFileSize(file_path, &file_size));
331 EXPECT_EQ(static_cast<int64>(i), file_size);
332 }
333 }
334
305 } // namespace 335 } // namespace
OLDNEW
« no previous file with comments | « third_party/zlib/google/zip_reader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698