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 "base/pickle.h" | 5 #include "base/pickle.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include <algorithm> // for max() | 9 #include <algorithm> // for max() |
10 | 10 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 : header_(NULL), | 163 : header_(NULL), |
164 header_size_(AlignInt(header_size, sizeof(uint32))), | 164 header_size_(AlignInt(header_size, sizeof(uint32))), |
165 capacity_(0), | 165 capacity_(0), |
166 variable_buffer_offset_(0) { | 166 variable_buffer_offset_(0) { |
167 DCHECK_GE(static_cast<size_t>(header_size), sizeof(Header)); | 167 DCHECK_GE(static_cast<size_t>(header_size), sizeof(Header)); |
168 DCHECK_LE(header_size, kPayloadUnit); | 168 DCHECK_LE(header_size, kPayloadUnit); |
169 Resize(kPayloadUnit); | 169 Resize(kPayloadUnit); |
170 header_->payload_size = 0; | 170 header_->payload_size = 0; |
171 } | 171 } |
172 | 172 |
173 Pickle::Pickle(const char* data, int data_len) | 173 Pickle::Pickle(const char* data, size_t data_len) |
174 : header_(reinterpret_cast<Header*>(const_cast<char*>(data))), | 174 : header_(reinterpret_cast<Header*>(const_cast<char*>(data))), |
175 header_size_(0), | 175 header_size_(0), |
176 capacity_(kCapacityReadOnly), | 176 capacity_(kCapacityReadOnly), |
177 variable_buffer_offset_(0) { | 177 variable_buffer_offset_(0) { |
178 if (data_len >= static_cast<int>(sizeof(Header))) | 178 if (data_len >= sizeof(Header)) |
179 header_size_ = data_len - header_->payload_size; | 179 header_size_ = data_len - header_->payload_size; |
180 | 180 |
181 if (header_size_ > static_cast<unsigned int>(data_len)) | 181 if (header_size_ > data_len) |
182 header_size_ = 0; | 182 header_size_ = 0; |
183 | 183 |
184 if (header_size_ != AlignInt(header_size_, sizeof(uint32))) | 184 if (header_size_ != AlignInt(header_size_, sizeof(uint32))) |
185 header_size_ = 0; | 185 header_size_ = 0; |
186 | 186 |
187 // If there is anything wrong with the data, we're not going to use it. | 187 // If there is anything wrong with the data, we're not going to use it. |
188 if (!header_size_) | 188 if (!header_size_) |
189 header_ = NULL; | 189 header_ = NULL; |
190 } | 190 } |
191 | 191 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 return NULL; | 352 return NULL; |
353 | 353 |
354 const Header* hdr = reinterpret_cast<const Header*>(start); | 354 const Header* hdr = reinterpret_cast<const Header*>(start); |
355 const char* payload_base = start + header_size; | 355 const char* payload_base = start + header_size; |
356 const char* payload_end = payload_base + hdr->payload_size; | 356 const char* payload_end = payload_base + hdr->payload_size; |
357 if (payload_end < payload_base) | 357 if (payload_end < payload_base) |
358 return NULL; | 358 return NULL; |
359 | 359 |
360 return (payload_end > end) ? NULL : payload_end; | 360 return (payload_end > end) ? NULL : payload_end; |
361 } | 361 } |
OLD | NEW |