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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // 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. |
141 base::string16 file_name_utf16; | 141 base::string16 file_name_utf16; |
142 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(), |
143 &file_name_utf16)) { | 143 &file_name_utf16)) { |
144 is_unsafe_ = true; | 144 is_unsafe_ = true; |
145 } | 145 } |
146 | 146 |
147 // We also consider that the file name is unsafe, if it's absolute. | 147 // We also consider that the file name is unsafe, if it's absolute. |
148 // On Windows, IsAbsolute() returns false for paths starting with "/". | 148 // On Windows, IsAbsolute() returns false for paths starting with "/". |
149 if (file_path_.IsAbsolute() || | 149 if (file_path_.IsAbsolute() || |
150 base::StartsWithASCII(file_name_in_zip, "/", false)) | 150 base::StartsWith(file_name_in_zip, "/", |
| 151 base::CompareCase::INSENSITIVE_ASCII)) |
151 is_unsafe_ = true; | 152 is_unsafe_ = true; |
152 | 153 |
153 // Construct the last modified time. The timezone info is not present in | 154 // Construct the last modified time. The timezone info is not present in |
154 // zip files, so we construct the time as local time. | 155 // zip files, so we construct the time as local time. |
155 base::Time::Exploded exploded_time = {}; // Zero-clear. | 156 base::Time::Exploded exploded_time = {}; // Zero-clear. |
156 exploded_time.year = raw_file_info.tmu_date.tm_year; | 157 exploded_time.year = raw_file_info.tmu_date.tm_year; |
157 // The month in zip file is 0-based, whereas ours is 1-based. | 158 // The month in zip file is 0-based, whereas ours is 1-based. |
158 exploded_time.month = raw_file_info.tmu_date.tm_mon + 1; | 159 exploded_time.month = raw_file_info.tmu_date.tm_mon + 1; |
159 exploded_time.day_of_month = raw_file_info.tmu_date.tm_mday; | 160 exploded_time.day_of_month = raw_file_info.tmu_date.tm_mday; |
160 exploded_time.hour = raw_file_info.tmu_date.tm_hour; | 161 exploded_time.hour = raw_file_info.tmu_date.tm_hour; |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 } | 534 } |
534 | 535 |
535 bool FileWriterDelegate::WriteBytes(const char* data, int num_bytes) { | 536 bool FileWriterDelegate::WriteBytes(const char* data, int num_bytes) { |
536 int bytes_written = file_->WriteAtCurrentPos(data, num_bytes); | 537 int bytes_written = file_->WriteAtCurrentPos(data, num_bytes); |
537 if (bytes_written > 0) | 538 if (bytes_written > 0) |
538 file_length_ += bytes_written; | 539 file_length_ += bytes_written; |
539 return bytes_written == num_bytes; | 540 return bytes_written == num_bytes; |
540 } | 541 } |
541 | 542 |
542 } // namespace zip | 543 } // namespace zip |
OLD | NEW |