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