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

Side by Side Diff: base/pickle_unittest.cc

Issue 146121: Fix a couple of integer issues in Pickle deserialization (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « base/pickle.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace { 13 namespace {
13 14
14 const int testint = 2093847192; 15 const int testint = 2093847192;
15 const std::string teststr("Hello world"); // note non-aligned string length 16 const std::string teststr("Hello world"); // note non-aligned string length
16 const std::wstring testwstr(L"Hello, world"); 17 const std::wstring testwstr(L"Hello, world");
17 const char testdata[] = "AAA\0BBB\0"; 18 const char testdata[] = "AAA\0BBB\0";
18 const int testdatalen = arraysize(testdata) - 1; 19 const int testdatalen = arraysize(testdata) - 1;
19 const bool testbool1 = false; 20 const bool testbool1 = false;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 TEST(PickleTest, EqualsOperator) { 212 TEST(PickleTest, EqualsOperator) {
212 Pickle source; 213 Pickle source;
213 source.WriteInt(1); 214 source.WriteInt(1);
214 215
215 Pickle copy_refs_source_buffer(static_cast<const char*>(source.data()), 216 Pickle copy_refs_source_buffer(static_cast<const char*>(source.data()),
216 source.size()); 217 source.size());
217 Pickle copy; 218 Pickle copy;
218 copy = copy_refs_source_buffer; 219 copy = copy_refs_source_buffer;
219 ASSERT_EQ(source.size(), copy.size()); 220 ASSERT_EQ(source.size(), copy.size());
220 } 221 }
222
223 TEST(PickleTest, EvilLengths) {
224 Pickle source;
225 std::string str(10000, 'A');
226 source.WriteData(str.c_str(), 100000);
227 // ReadString16 used to have its read buffer length calculation wrong leading
228 // to out-of-bounds reading.
229 void* iter = NULL;
230 string16 str16;
231 EXPECT_FALSE(source.ReadString16(&iter, &str16));
232
233 // And check we didn't break ReadString16.
234 str16 = (wchar_t) 'A';
235 Pickle str16_pickle;
236 str16_pickle.WriteString16(str16);
237 iter = NULL;
238 EXPECT_TRUE(str16_pickle.ReadString16(&iter, &str16));
239 EXPECT_EQ(1U, str16.length());
240
241 // Check we don't fail in a length check with large WStrings.
242 Pickle big_len;
243 big_len.WriteInt(1 << 30);
244 iter = NULL;
245 std::wstring wstr;
246 EXPECT_FALSE(big_len.ReadWString(&iter, &wstr));
247 }
248
OLDNEW
« no previous file with comments | « base/pickle.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698