Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1187)

Side by Side Diff: components/safe_browsing_db/v4_rice.cc

Issue 2190233002: Rice decode removals and additions and use them to update the store. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@01_v4_rice
Patch Set: Remove DVLOGs. Add tests (not proud of the last test). Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/logging.h" 5 #include "base/logging.h"
6 #include "base/numerics/safe_math.h" 6 #include "base/numerics/safe_math.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "components/safe_browsing_db/v4_rice.h" 8 #include "components/safe_browsing_db/v4_rice.h"
9 9
10 using ::google::protobuf::RepeatedField; 10 using ::google::protobuf::RepeatedField;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 const int32 num_entries, 99 const int32 num_entries,
100 const std::string& encoded_data, 100 const std::string& encoded_data,
101 std::string* out) { 101 std::string* out) {
102 DCHECK(out); 102 DCHECK(out);
103 103
104 V4DecodeResult result = 104 V4DecodeResult result =
105 ValidateInput(rice_parameter, num_entries, encoded_data); 105 ValidateInput(rice_parameter, num_entries, encoded_data);
106 if (result != DECODE_SUCCESS) { 106 if (result != DECODE_SUCCESS) {
107 return result; 107 return result;
108 } 108 }
109 out->reserve((num_entries + 1) * 4);
109 110
110 out->reserve((num_entries + 1) * 4); 111 // Cast to unsigned since we don't look at the sign bit as a sign bit.
112 // first_value should have been an unsigned to begin with but proto don't
113 // allow that.
114 uint32_t first_value_unsigned = static_cast<uint32_t>(first_value);
115 base::CheckedNumeric<uint32_t> last_value(first_value_unsigned);
111 char bytes[4]; 116 char bytes[4];
112 base::CheckedNumeric<uint32_t> last_value(first_value);
113 GetBytesFromUInt32(last_value.ValueOrDie(), bytes); 117 GetBytesFromUInt32(last_value.ValueOrDie(), bytes);
114 out->append(bytes, 4); 118 out->append(bytes, 4);
115 119
116 if (num_entries == 0) { 120 if (num_entries == 0) {
117 return DECODE_SUCCESS; 121 return DECODE_SUCCESS;
118 } 122 }
119 123
120 V4RiceDecoder decoder(rice_parameter, num_entries, encoded_data); 124 V4RiceDecoder decoder(rice_parameter, num_entries, encoded_data);
121 while (decoder.HasAnotherValue()) { 125 while (decoder.HasAnotherValue()) {
122 uint32_t offset; 126 uint32_t offset;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 current_word_, data_byte_index_, current_word_bit_index_, 270 current_word_, data_byte_index_, current_word_bit_index_,
267 rice_parameter_); 271 rice_parameter_);
268 } 272 }
269 273
270 std::ostream& operator<<(std::ostream& os, const V4RiceDecoder& rice_decoder) { 274 std::ostream& operator<<(std::ostream& os, const V4RiceDecoder& rice_decoder) {
271 os << rice_decoder.DebugString(); 275 os << rice_decoder.DebugString();
272 return os; 276 return os;
273 } 277 }
274 278
275 } // namespace safe_browsing 279 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | components/safe_browsing_db/v4_store.h » ('j') | components/safe_browsing_db/v4_store.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698