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, "/", false); | 134 is_directory_ = base::EndsWith(file_name_in_zip, "/", |
| 135 base::CompareCase::INSENSITIVE_ASCII); |
135 | 136 |
136 // Check the file name here for directory traversal issues. | 137 // Check the file name here for directory traversal issues. |
137 is_unsafe_ = file_path_.ReferencesParent(); | 138 is_unsafe_ = file_path_.ReferencesParent(); |
138 | 139 |
139 // We also consider that the file name is unsafe, if it's invalid UTF-8. | 140 // We also consider that the file name is unsafe, if it's invalid UTF-8. |
140 base::string16 file_name_utf16; | 141 base::string16 file_name_utf16; |
141 if (!base::UTF8ToUTF16(file_name_in_zip.data(), file_name_in_zip.size(), | 142 if (!base::UTF8ToUTF16(file_name_in_zip.data(), file_name_in_zip.size(), |
142 &file_name_utf16)) { | 143 &file_name_utf16)) { |
143 is_unsafe_ = true; | 144 is_unsafe_ = true; |
144 } | 145 } |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 } | 533 } |
533 | 534 |
534 bool FileWriterDelegate::WriteBytes(const char* data, int num_bytes) { | 535 bool FileWriterDelegate::WriteBytes(const char* data, int num_bytes) { |
535 int bytes_written = file_->WriteAtCurrentPos(data, num_bytes); | 536 int bytes_written = file_->WriteAtCurrentPos(data, num_bytes); |
536 if (bytes_written > 0) | 537 if (bytes_written > 0) |
537 file_length_ += bytes_written; | 538 file_length_ += bytes_written; |
538 return bytes_written == num_bytes; | 539 return bytes_written == num_bytes; |
539 } | 540 } |
540 | 541 |
541 } // namespace zip | 542 } // namespace zip |
OLD | NEW |