OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "net/disk_cache/simple/simple_synchronous_entry.h" | 5 #include "net/disk_cache/simple/simple_synchronous_entry.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <functional> | 9 #include <functional> |
10 #include <limits> | 10 #include <limits> |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 } | 658 } |
659 | 659 |
660 void SimpleSynchronousEntry::CheckEOFRecord(int index, | 660 void SimpleSynchronousEntry::CheckEOFRecord(int index, |
661 const SimpleEntryStat& entry_stat, | 661 const SimpleEntryStat& entry_stat, |
662 uint32_t expected_crc32, | 662 uint32_t expected_crc32, |
663 int* out_result) const { | 663 int* out_result) const { |
664 DCHECK(initialized_); | 664 DCHECK(initialized_); |
665 uint32_t crc32; | 665 uint32_t crc32; |
666 bool has_crc32; | 666 bool has_crc32; |
667 bool has_key_sha256; | 667 bool has_key_sha256; |
668 int stream_size; | 668 int32_t stream_size; |
669 *out_result = GetEOFRecordData(index, entry_stat, &has_crc32, &has_key_sha256, | 669 *out_result = GetEOFRecordData(index, entry_stat, &has_crc32, &has_key_sha256, |
670 &crc32, &stream_size); | 670 &crc32, &stream_size); |
671 if (*out_result != net::OK) { | 671 if (*out_result != net::OK) { |
672 Doom(); | 672 Doom(); |
673 return; | 673 return; |
674 } | 674 } |
675 if (has_crc32 && crc32 != expected_crc32) { | 675 if (has_crc32 && crc32 != expected_crc32) { |
676 DVLOG(1) << "EOF record had bad crc."; | 676 DVLOG(1) << "EOF record had bad crc."; |
677 *out_result = net::ERR_CACHE_CHECKSUM_MISMATCH; | 677 *out_result = net::ERR_CACHE_CHECKSUM_MISMATCH; |
678 RecordCheckEOFResult(cache_type_, CHECK_EOF_RESULT_CRC_MISMATCH); | 678 RecordCheckEOFResult(cache_type_, CHECK_EOF_RESULT_CRC_MISMATCH); |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1170 // the actual size of stream 0. | 1170 // the actual size of stream 0. |
1171 int total_data_size = GetDataSizeFromFileSize(key_.size(), file_size); | 1171 int total_data_size = GetDataSizeFromFileSize(key_.size(), file_size); |
1172 out_entry_stat->set_data_size(0, 0); | 1172 out_entry_stat->set_data_size(0, 0); |
1173 out_entry_stat->set_data_size( | 1173 out_entry_stat->set_data_size( |
1174 1, | 1174 1, |
1175 total_data_size - sizeof(net::SHA256HashValue) - sizeof(SimpleFileEOF)); | 1175 total_data_size - sizeof(net::SHA256HashValue) - sizeof(SimpleFileEOF)); |
1176 | 1176 |
1177 bool has_crc32; | 1177 bool has_crc32; |
1178 bool has_key_sha256; | 1178 bool has_key_sha256; |
1179 uint32_t read_crc32; | 1179 uint32_t read_crc32; |
1180 int stream_0_size; | 1180 int32_t stream_0_size; |
1181 int ret_value_crc32 = | 1181 int ret_value_crc32 = |
1182 GetEOFRecordData(0, *out_entry_stat, &has_crc32, &has_key_sha256, | 1182 GetEOFRecordData(0, *out_entry_stat, &has_crc32, &has_key_sha256, |
1183 &read_crc32, &stream_0_size); | 1183 &read_crc32, &stream_0_size); |
1184 if (ret_value_crc32 != net::OK) | 1184 if (ret_value_crc32 != net::OK) |
1185 return ret_value_crc32; | 1185 return ret_value_crc32; |
1186 | |
1186 // Calculate and set the real values for data size. | 1187 // Calculate and set the real values for data size. |
1187 int stream_1_size = out_entry_stat->data_size(1) - stream_0_size; | 1188 int32_t stream_1_size = out_entry_stat->data_size(1); |
1188 if (!has_key_sha256) | 1189 if (!has_key_sha256) |
1189 stream_1_size += sizeof(net::SHA256HashValue); | 1190 stream_1_size += sizeof(net::SHA256HashValue); |
1190 if (stream_1_size < 0) | 1191 if (stream_0_size > stream_1_size) |
Julia Tuttle
2016/06/27 20:39:10
This conditional sounds nonsensical. It makes sens
gavinp
2016/07/26 17:32:34
Done.
| |
1191 return net::ERR_FAILED; | 1192 return net::ERR_FAILED; |
1193 stream_1_size -= stream_0_size; | |
1192 out_entry_stat->set_data_size(0, stream_0_size); | 1194 out_entry_stat->set_data_size(0, stream_0_size); |
1193 out_entry_stat->set_data_size(1, stream_1_size); | 1195 out_entry_stat->set_data_size(1, stream_1_size); |
1194 | 1196 |
1195 // Put stream 0 data in memory. | 1197 // Put stream 0 data in memory. |
1196 *stream_0_data = new net::GrowableIOBuffer(); | 1198 *stream_0_data = new net::GrowableIOBuffer(); |
1197 (*stream_0_data)->SetCapacity(stream_0_size + sizeof(net::SHA256HashValue)); | 1199 (*stream_0_data)->SetCapacity(stream_0_size + sizeof(net::SHA256HashValue)); |
1198 int file_offset = out_entry_stat->GetOffsetInFile(key_.size(), 0, 0); | 1200 int file_offset = out_entry_stat->GetOffsetInFile(key_.size(), 0, 0); |
1199 int read_size = stream_0_size; | 1201 int read_size = stream_0_size; |
1200 if (has_key_sha256) | 1202 if (has_key_sha256) |
1201 read_size += sizeof(net::SHA256HashValue); | 1203 read_size += sizeof(net::SHA256HashValue); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1257 RecordCheckEOFResult(cache_type_, CHECK_EOF_RESULT_READ_FAILURE); | 1259 RecordCheckEOFResult(cache_type_, CHECK_EOF_RESULT_READ_FAILURE); |
1258 return net::ERR_CACHE_CHECKSUM_READ_FAILURE; | 1260 return net::ERR_CACHE_CHECKSUM_READ_FAILURE; |
1259 } | 1261 } |
1260 | 1262 |
1261 if (eof_record.final_magic_number != kSimpleFinalMagicNumber) { | 1263 if (eof_record.final_magic_number != kSimpleFinalMagicNumber) { |
1262 RecordCheckEOFResult(cache_type_, CHECK_EOF_RESULT_MAGIC_NUMBER_MISMATCH); | 1264 RecordCheckEOFResult(cache_type_, CHECK_EOF_RESULT_MAGIC_NUMBER_MISMATCH); |
1263 DVLOG(1) << "EOF record had bad magic number."; | 1265 DVLOG(1) << "EOF record had bad magic number."; |
1264 return net::ERR_CACHE_CHECKSUM_READ_FAILURE; | 1266 return net::ERR_CACHE_CHECKSUM_READ_FAILURE; |
1265 } | 1267 } |
1266 | 1268 |
1269 if (!base::IsValueInRangeForNumericType<int>(eof_record.stream_size)) | |
Julia Tuttle
2016/06/27 20:39:10
int, or int32_t? (Also, do you want to check for n
gavinp
2016/07/26 17:32:34
Great catch. Fixed the signature. Thanks.
Don't n
| |
1270 return net::ERR_FAILED; | |
1271 | |
1267 *out_has_crc32 = (eof_record.flags & SimpleFileEOF::FLAG_HAS_CRC32) == | 1272 *out_has_crc32 = (eof_record.flags & SimpleFileEOF::FLAG_HAS_CRC32) == |
1268 SimpleFileEOF::FLAG_HAS_CRC32; | 1273 SimpleFileEOF::FLAG_HAS_CRC32; |
1269 *out_has_key_sha256 = | 1274 *out_has_key_sha256 = |
1270 (eof_record.flags & SimpleFileEOF::FLAG_HAS_KEY_SHA256) == | 1275 (eof_record.flags & SimpleFileEOF::FLAG_HAS_KEY_SHA256) == |
1271 SimpleFileEOF::FLAG_HAS_KEY_SHA256; | 1276 SimpleFileEOF::FLAG_HAS_KEY_SHA256; |
1272 *out_crc32 = eof_record.data_crc32; | 1277 *out_crc32 = eof_record.data_crc32; |
1273 *out_data_size = eof_record.stream_size; | 1278 *out_data_size = eof_record.stream_size; |
1274 SIMPLE_CACHE_UMA(BOOLEAN, "SyncCheckEOFHasCrc", cache_type_, *out_has_crc32); | 1279 SIMPLE_CACHE_UMA(BOOLEAN, "SyncCheckEOFHasCrc", cache_type_, *out_has_crc32); |
1275 return net::OK; | 1280 return net::OK; |
1276 } | 1281 } |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1589 range.offset = offset; | 1594 range.offset = offset; |
1590 range.length = len; | 1595 range.length = len; |
1591 range.data_crc32 = data_crc32; | 1596 range.data_crc32 = data_crc32; |
1592 range.file_offset = data_file_offset; | 1597 range.file_offset = data_file_offset; |
1593 sparse_ranges_.insert(std::make_pair(offset, range)); | 1598 sparse_ranges_.insert(std::make_pair(offset, range)); |
1594 | 1599 |
1595 return true; | 1600 return true; |
1596 } | 1601 } |
1597 | 1602 |
1598 } // namespace disk_cache | 1603 } // namespace disk_cache |
OLD | NEW |