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

Side by Side Diff: test/cctest/test-api.cc

Issue 1226493003: unicode-decoder: fix out-of-band write in utf16 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fixes Created 5 years, 5 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
« no previous file with comments | « src/unicode-decoder.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 7400 matching lines...) Expand 10 before | Expand all | Expand 10 after
7411 Local<Value> s4 = global->Get(v8_str("sym4")); 7411 Local<Value> s4 = global->Get(v8_str("sym4"));
7412 CHECK(SameSymbol(sym0, Handle<String>::Cast(s0))); 7412 CHECK(SameSymbol(sym0, Handle<String>::Cast(s0)));
7413 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b))); 7413 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b)));
7414 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1))); 7414 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1)));
7415 CHECK(SameSymbol(sym2, Handle<String>::Cast(s2))); 7415 CHECK(SameSymbol(sym2, Handle<String>::Cast(s2)));
7416 CHECK(SameSymbol(sym3, Handle<String>::Cast(s3))); 7416 CHECK(SameSymbol(sym3, Handle<String>::Cast(s3)));
7417 CHECK(SameSymbol(sym4, Handle<String>::Cast(s4))); 7417 CHECK(SameSymbol(sym4, Handle<String>::Cast(s4)));
7418 } 7418 }
7419 7419
7420 7420
7421 THREADED_TEST(Utf16MissingTrailing) {
7422 LocalContext context;
7423 v8::HandleScope scope(context->GetIsolate());
7424
7425 // Make sure it will go past the buffer, so it will call `WriteUtf16Slow`
7426 int size = 1024 * 64;
7427 uint8_t* buffer = new uint8_t[size];
7428 for (int i = 0; i < size; i += 4) {
7429 buffer[i] = 0xf0;
7430 buffer[i + 1] = 0x9d;
7431 buffer[i + 2] = 0x80;
7432 buffer[i + 3] = 0x9e;
7433 }
7434
7435 // Now invoke the decoder without last 3 bytes
7436 v8::Local<v8::String> str =
7437 v8::String::NewFromUtf8(
7438 context->GetIsolate(), reinterpret_cast<char*>(buffer),
7439 v8::NewStringType::kNormal, size - 3).ToLocalChecked();
7440 USE(str);
7441 delete[] buffer;
7442 }
7443
7444
7445 THREADED_TEST(Utf16Trailing3Byte) {
7446 LocalContext context;
7447 v8::HandleScope scope(context->GetIsolate());
7448
7449 // Make sure it will go past the buffer, so it will call `WriteUtf16Slow`
7450 int size = 1024 * 63;
7451 uint8_t* buffer = new uint8_t[size];
7452 for (int i = 0; i < size; i += 3) {
7453 buffer[i] = 0xe2;
7454 buffer[i + 1] = 0x80;
7455 buffer[i + 2] = 0xa6;
7456 }
7457
7458 // Now invoke the decoder without last 3 bytes
7459 v8::Local<v8::String> str =
7460 v8::String::NewFromUtf8(
7461 context->GetIsolate(), reinterpret_cast<char*>(buffer),
7462 v8::NewStringType::kNormal, size).ToLocalChecked();
7463
7464 v8::String::Value value(str);
7465 CHECK_EQ(value.length(), size / 3);
7466 CHECK_EQ((*value)[value.length() - 1], 0x2026);
7467
7468 delete[] buffer;
7469 }
7470
7471
7421 THREADED_TEST(ToArrayIndex) { 7472 THREADED_TEST(ToArrayIndex) {
7422 LocalContext context; 7473 LocalContext context;
7423 v8::Isolate* isolate = context->GetIsolate(); 7474 v8::Isolate* isolate = context->GetIsolate();
7424 v8::HandleScope scope(isolate); 7475 v8::HandleScope scope(isolate);
7425 7476
7426 v8::Handle<String> str = v8_str("42"); 7477 v8::Handle<String> str = v8_str("42");
7427 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); 7478 v8::Handle<v8::Uint32> index = str->ToArrayIndex();
7428 CHECK(!index.IsEmpty()); 7479 CHECK(!index.IsEmpty());
7429 CHECK_EQ(42.0, index->Uint32Value()); 7480 CHECK_EQ(42.0, index->Uint32Value());
7430 str = v8_str("42asdf"); 7481 str = v8_str("42asdf");
(...skipping 14311 matching lines...) Expand 10 before | Expand all | Expand 10 after
21742 CHECK(set->Has(env.local(), set).FromJust()); 21793 CHECK(set->Has(env.local(), set).FromJust());
21743 21794
21744 CHECK(set->Delete(env.local(), set).FromJust()); 21795 CHECK(set->Delete(env.local(), set).FromJust());
21745 CHECK_EQ(2U, set->Size()); 21796 CHECK_EQ(2U, set->Size());
21746 CHECK(!set->Has(env.local(), set).FromJust()); 21797 CHECK(!set->Has(env.local(), set).FromJust());
21747 CHECK(!set->Delete(env.local(), set).FromJust()); 21798 CHECK(!set->Delete(env.local(), set).FromJust());
21748 21799
21749 set->Clear(); 21800 set->Clear();
21750 CHECK_EQ(0U, set->Size()); 21801 CHECK_EQ(0U, set->Size());
21751 } 21802 }
OLDNEW
« no previous file with comments | « src/unicode-decoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698