| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/common/zip.h" | 5 #include "chrome/common/zip.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 filename = UTF8ToWide(filename_inzip); | 42 filename = UTF8ToWide(filename_inzip); |
| 43 #elif defined(OS_POSIX) | 43 #elif defined(OS_POSIX) |
| 44 filename = filename_inzip; | 44 filename = filename_inzip; |
| 45 #endif | 45 #endif |
| 46 | 46 |
| 47 // Check the filename here for directory traversal issues. In the name of | 47 // Check the filename here for directory traversal issues. In the name of |
| 48 // simplicity and security, we might reject a valid filename such as "a..b". | 48 // simplicity and security, we might reject a valid filename such as "a..b". |
| 49 if (filename.find(FILE_PATH_LITERAL("..")) != FilePath::StringType::npos) | 49 if (filename.find(FILE_PATH_LITERAL("..")) != FilePath::StringType::npos) |
| 50 return false; | 50 return false; |
| 51 | 51 |
| 52 SplitString(filename, '/', &filename_parts); | 52 base::SplitString(filename, '/', &filename_parts); |
| 53 | 53 |
| 54 FilePath dest_file(dest_dir); | 54 FilePath dest_file(dest_dir); |
| 55 std::vector<FilePath::StringType>::iterator iter; | 55 std::vector<FilePath::StringType>::iterator iter; |
| 56 for (iter = filename_parts.begin(); iter != filename_parts.end(); ++iter) | 56 for (iter = filename_parts.begin(); iter != filename_parts.end(); ++iter) |
| 57 dest_file = dest_file.Append(*iter); | 57 dest_file = dest_file.Append(*iter); |
| 58 | 58 |
| 59 // If this is a directory, just create it and return. | 59 // If this is a directory, just create it and return. |
| 60 if (filename_inzip[strlen(filename_inzip) - 1] == '/') { | 60 if (filename_inzip[strlen(filename_inzip) - 1] == '/') { |
| 61 if (!file_util::CreateDirectory(dest_file)) | 61 if (!file_util::CreateDirectory(dest_file)) |
| 62 return false; | 62 return false; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 } | 305 } |
| 306 } | 306 } |
| 307 | 307 |
| 308 if (ZIP_OK != zipClose(zip_file, NULL)) { // global comment | 308 if (ZIP_OK != zipClose(zip_file, NULL)) { // global comment |
| 309 LOG(ERROR) << "Error closing zip file " << dest_file_str; | 309 LOG(ERROR) << "Error closing zip file " << dest_file_str; |
| 310 return false; | 310 return false; |
| 311 } | 311 } |
| 312 | 312 |
| 313 return success; | 313 return success; |
| 314 } | 314 } |
| OLD | NEW |