| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "third_party/zlib/google/zip_reader.h" | 5 #include "third_party/zlib/google/zip_reader.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 // TODO(satorux): The implementation assumes that file names in zip files | 124 // TODO(satorux): The implementation assumes that file names in zip files |
| 125 // are encoded in UTF-8. This is true for zip files created by Zip() | 125 // are encoded in UTF-8. This is true for zip files created by Zip() |
| 126 // function in zip.h, but not true for user-supplied random zip files. | 126 // function in zip.h, but not true for user-supplied random zip files. |
| 127 ZipReader::EntryInfo::EntryInfo(const std::string& file_name_in_zip, | 127 ZipReader::EntryInfo::EntryInfo(const std::string& file_name_in_zip, |
| 128 const unz_file_info& raw_file_info) | 128 const unz_file_info& raw_file_info) |
| 129 : file_path_(base::FilePath::FromUTF8Unsafe(file_name_in_zip)), | 129 : file_path_(base::FilePath::FromUTF8Unsafe(file_name_in_zip)), |
| 130 is_directory_(false) { | 130 is_directory_(false) { |
| 131 original_size_ = raw_file_info.uncompressed_size; | 131 original_size_ = raw_file_info.uncompressed_size; |
| 132 | 132 |
| 133 // Directory entries in zip files end with "/". | 133 // Directory entries in zip files end with "/". |
| 134 is_directory_ = base::EndsWith(file_name_in_zip, "/", | 134 is_directory_ = base::EndsWith(file_name_in_zip, "/", false); |
| 135 base::CompareCase::INSENSITIVE_ASCII); | |
| 136 | 135 |
| 137 // Check the file name here for directory traversal issues. | 136 // Check the file name here for directory traversal issues. |
| 138 is_unsafe_ = file_path_.ReferencesParent(); | 137 is_unsafe_ = file_path_.ReferencesParent(); |
| 139 | 138 |
| 140 // We also consider that the file name is unsafe, if it's invalid UTF-8. | 139 // We also consider that the file name is unsafe, if it's invalid UTF-8. |
| 141 base::string16 file_name_utf16; | 140 base::string16 file_name_utf16; |
| 142 if (!base::UTF8ToUTF16(file_name_in_zip.data(), file_name_in_zip.size(), | 141 if (!base::UTF8ToUTF16(file_name_in_zip.data(), file_name_in_zip.size(), |
| 143 &file_name_utf16)) { | 142 &file_name_utf16)) { |
| 144 is_unsafe_ = true; | 143 is_unsafe_ = true; |
| 145 } | 144 } |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 } | 532 } |
| 534 | 533 |
| 535 bool FileWriterDelegate::WriteBytes(const char* data, int num_bytes) { | 534 bool FileWriterDelegate::WriteBytes(const char* data, int num_bytes) { |
| 536 int bytes_written = file_->WriteAtCurrentPos(data, num_bytes); | 535 int bytes_written = file_->WriteAtCurrentPos(data, num_bytes); |
| 537 if (bytes_written > 0) | 536 if (bytes_written > 0) |
| 538 file_length_ += bytes_written; | 537 file_length_ += bytes_written; |
| 539 return bytes_written == num_bytes; | 538 return bytes_written == num_bytes; |
| 540 } | 539 } |
| 541 | 540 |
| 542 } // namespace zip | 541 } // namespace zip |
| OLD | NEW |