From 59b9a32b34d3724157aa8883a81213abe7be61d8 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Tue, 11 Sep 2012 14:16:56 +0000 Subject: [PATCH] Fix edge case of extension with NULL as source string. BUG=144649 Review URL: https://chromiumcodereview.appspot.com/10914201 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12485 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/api.cc | 4 +++- src/objects.h | 2 +- test/cctest/test-api.cc | 12 ++++++++++++ test/cctest/test-strings.cc | 7 +++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/api.cc b/src/api.cc index 8b323b2..5c76e32 100644 --- a/src/api.cc +++ b/src/api.cc @@ -541,7 +541,9 @@ Extension::Extension(const char* name, source_(source, source_length_), dep_count_(dep_count), deps_(deps), - auto_enable_(false) { } + auto_enable_(false) { + CHECK(source != NULL || source_length_ == 0); +} v8::Handle Undefined() { diff --git a/src/objects.h b/src/objects.h index 9b33a43..45a2ac0 100644 --- a/src/objects.h +++ b/src/objects.h @@ -7386,7 +7386,7 @@ class String: public HeapObject { #ifdef V8_HOST_CAN_READ_UNALIGNED ASSERT(kMaxAsciiCharCode == 0x7F); const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80; - while (chars <= limit - sizeof(uintptr_t)) { + while (chars + sizeof(uintptr_t) <= limit) { if (*reinterpret_cast(chars) & non_ascii_mask) { return false; } diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index f7d8d80..4bd99a6 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -4671,6 +4671,18 @@ THREADED_TEST(SimpleExtensions) { } +THREADED_TEST(NullExtensions) { + v8::HandleScope handle_scope; + v8::RegisterExtension(new Extension("nulltest", NULL)); + const char* extension_names[] = { "nulltest" }; + v8::ExtensionConfiguration extensions(1, extension_names); + v8::Handle context = Context::New(&extensions); + Context::Scope lock(context); + v8::Handle result = Script::Compile(v8_str("1+3"))->Run(); + CHECK_EQ(result, v8::Integer::New(4)); +} + + static const char* kEmbeddedExtensionSource = "function Ret54321(){return 54321;}~~@@$" "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc index 4557100..5a9ccbb 100644 --- a/test/cctest/test-strings.cc +++ b/test/cctest/test-strings.cc @@ -11,6 +11,7 @@ #include "api.h" #include "factory.h" +#include "objects.h" #include "cctest.h" #include "zone-inl.h" @@ -708,3 +709,9 @@ TEST(StringReplaceAtomTwoByteResult) { v8::Local expected = v8_str("ascii\x80only\x80string\x80"); CHECK(expected->Equals(result)); } + + +TEST(IsAscii) { + CHECK(String::IsAscii(static_cast(NULL), 0)); + CHECK(String::IsAscii(static_cast(NULL), 0)); +} -- 2.7.4