| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 215 |
| 216 Pickle copy_refs_source_buffer(static_cast<const char*>(source.data()), | 216 Pickle copy_refs_source_buffer(static_cast<const char*>(source.data()), |
| 217 source.size()); | 217 source.size()); |
| 218 Pickle copy; | 218 Pickle copy; |
| 219 copy = copy_refs_source_buffer; | 219 copy = copy_refs_source_buffer; |
| 220 ASSERT_EQ(source.size(), copy.size()); | 220 ASSERT_EQ(source.size(), copy.size()); |
| 221 } | 221 } |
| 222 | 222 |
| 223 TEST(PickleTest, EvilLengths) { | 223 TEST(PickleTest, EvilLengths) { |
| 224 Pickle source; | 224 Pickle source; |
| 225 std::string str(10000, 'A'); | 225 std::string str(100000, 'A'); |
| 226 source.WriteData(str.c_str(), 100000); | 226 source.WriteData(str.c_str(), 100000); |
| 227 // ReadString16 used to have its read buffer length calculation wrong leading | 227 // ReadString16 used to have its read buffer length calculation wrong leading |
| 228 // to out-of-bounds reading. | 228 // to out-of-bounds reading. |
| 229 void* iter = NULL; | 229 void* iter = NULL; |
| 230 string16 str16; | 230 string16 str16; |
| 231 EXPECT_FALSE(source.ReadString16(&iter, &str16)); | 231 EXPECT_FALSE(source.ReadString16(&iter, &str16)); |
| 232 | 232 |
| 233 // And check we didn't break ReadString16. | 233 // And check we didn't break ReadString16. |
| 234 str16 = (wchar_t) 'A'; | 234 str16 = (wchar_t) 'A'; |
| 235 Pickle str16_pickle; | 235 Pickle str16_pickle; |
| 236 str16_pickle.WriteString16(str16); | 236 str16_pickle.WriteString16(str16); |
| 237 iter = NULL; | 237 iter = NULL; |
| 238 EXPECT_TRUE(str16_pickle.ReadString16(&iter, &str16)); | 238 EXPECT_TRUE(str16_pickle.ReadString16(&iter, &str16)); |
| 239 EXPECT_EQ(1U, str16.length()); | 239 EXPECT_EQ(1U, str16.length()); |
| 240 | 240 |
| 241 // Check we don't fail in a length check with large WStrings. | 241 // Check we don't fail in a length check with large WStrings. |
| 242 Pickle big_len; | 242 Pickle big_len; |
| 243 big_len.WriteInt(1 << 30); | 243 big_len.WriteInt(1 << 30); |
| 244 iter = NULL; | 244 iter = NULL; |
| 245 std::wstring wstr; | 245 std::wstring wstr; |
| 246 EXPECT_FALSE(big_len.ReadWString(&iter, &wstr)); | 246 EXPECT_FALSE(big_len.ReadWString(&iter, &wstr)); |
| 247 } | 247 } |
| 248 | 248 |
| OLD | NEW |