Reviewers: ulan,
Message:
PTAL.
Description:
Fix edge case of extension with NULL as source string.
BUG=144649
Please review this at http://codereview.chromium.org/10914201/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/api.cc
M src/objects.h
M test/cctest/test-api.cc
M test/cctest/test-strings.cc
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
8b323b2f1fb7264f3b8da49cf1c491ec33c06742..5c76e32a1b4ec24734b2279c29c1ab8f0f1a428e
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<Primitive> Undefined() {
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index
9b33a4326c373b6508d2c097ed97e947b8a0776b..637dffba3c7711c2f96ba17e58ae10aa0a0b22c8
100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -7386,7 +7386,10 @@ 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)) {
+ // Forcing signed arithmetics to avoid integer underflow.
+ intptr_t unaligned_limit = reinterpret_cast<intptr_t>(limit);
+ unaligned_limit -= sizeof(uintptr_t);
+ while (reinterpret_cast<intptr_t>(chars) <= unaligned_limit) {
if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) {
return false;
}
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
f7d8d807698a80565d3da0d5863e8b372240431c..4bd99a6d9e940abd97ba243ecb383a119f4854f3
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 = Context::New(&extensions);
+ Context::Scope lock(context);
+ v8::Handle<Value> 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.";
Index: test/cctest/test-strings.cc
diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc
index
4557100e7ab1d1ec288d1135d0986ffb8264093c..5a9ccbb5790732cb0b42528860867bcbafa811be
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<v8::String> expected = v8_str("ascii\x80only\x80string\x80");
CHECK(expected->Equals(result));
}
+
+
+TEST(IsAscii) {
+ CHECK(String::IsAscii(static_cast<char*>(NULL), 0));
+ CHECK(String::IsAscii(static_cast<uc16*>(NULL), 0));
+}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev