Revision: 11622
Author:   [email protected]
Date:     Tue May 22 05:49:20 2012
Log:      Ensure integrity of ASCII strings.

BUG=v8:2128
TEST=

Review URL: https://chromiumcodereview.appspot.com/10407090
http://code.google.com/p/v8/source/detail?r=11622

Modified:
 /branches/bleeding_edge/src/d8.cc
 /branches/bleeding_edge/src/d8.h
 /branches/bleeding_edge/src/heap-inl.h
 /branches/bleeding_edge/src/heap.cc
 /branches/bleeding_edge/src/objects-debug.cc
 /branches/bleeding_edge/src/objects.h

=======================================
--- /branches/bleeding_edge/src/d8.cc   Wed May 16 08:48:06 2012
+++ /branches/bleeding_edge/src/d8.cc   Tue May 22 05:49:20 2012
@@ -834,8 +834,6 @@
   global_template->Set(String::New("print"), FunctionTemplate::New(Print));
   global_template->Set(String::New("write"), FunctionTemplate::New(Write));
   global_template->Set(String::New("read"), FunctionTemplate::New(Read));
-  global_template->Set(String::New("readbinary"),
-                       FunctionTemplate::New(ReadBinary));
   global_template->Set(String::New("readbuffer"),
                        FunctionTemplate::New(ReadBuffer));
   global_template->Set(String::New("readline"),
@@ -1054,23 +1052,6 @@
   *size_out = size;
   return chars;
 }
-
-
-Handle<Value> Shell::ReadBinary(const Arguments& args) {
-  String::Utf8Value filename(args[0]);
-  int size;
-  if (*filename == NULL) {
-    return ThrowException(String::New("Error loading file"));
-  }
-  char* chars = ReadChars(*filename, &size);
-  if (chars == NULL) {
-    return ThrowException(String::New("Error reading file"));
-  }
-  // We skip checking the string for UTF8 characters and use it raw as
-  // backing store for the external string with 8-bit characters.
-  BinaryResource* resource = new BinaryResource(chars, size);
-  return String::NewExternal(resource);
-}


 Handle<Value> Shell::ReadBuffer(const Arguments& args) {
=======================================
--- /branches/bleeding_edge/src/d8.h    Tue May 15 04:00:30 2012
+++ /branches/bleeding_edge/src/d8.h    Tue May 22 05:49:20 2012
@@ -307,7 +307,6 @@
   static Handle<Value> EnableProfiler(const Arguments& args);
   static Handle<Value> DisableProfiler(const Arguments& args);
   static Handle<Value> Read(const Arguments& args);
-  static Handle<Value> ReadBinary(const Arguments& args);
   static Handle<Value> ReadBuffer(const Arguments& args);
   static Handle<String> ReadFromStdin();
   static Handle<Value> ReadLine(const Arguments& args) {
=======================================
--- /branches/bleeding_edge/src/heap-inl.h      Wed Apr 11 02:23:57 2012
+++ /branches/bleeding_edge/src/heap-inl.h      Tue May 22 05:49:20 2012
@@ -595,12 +595,24 @@
 void ExternalStringTable::Verify() {
 #ifdef DEBUG
   for (int i = 0; i < new_space_strings_.length(); ++i) {
-    ASSERT(heap_->InNewSpace(new_space_strings_[i]));
-    ASSERT(new_space_strings_[i] != HEAP->raw_unchecked_the_hole_value());
+    Object* obj = Object::cast(new_space_strings_[i]);
+    // TODO(yangguo): check that the object is indeed an external string.
+    ASSERT(heap_->InNewSpace(obj));
+    ASSERT(obj != HEAP->raw_unchecked_the_hole_value());
+    if (obj->IsExternalAsciiString()) {
+      ExternalAsciiString* string = ExternalAsciiString::cast(obj);
+      ASSERT(String::IsAscii(string->GetChars(), string->length()));
+    }
   }
   for (int i = 0; i < old_space_strings_.length(); ++i) {
-    ASSERT(!heap_->InNewSpace(old_space_strings_[i]));
-    ASSERT(old_space_strings_[i] != HEAP->raw_unchecked_the_hole_value());
+    Object* obj = Object::cast(old_space_strings_[i]);
+    // TODO(yangguo): check that the object is indeed an external string.
+    ASSERT(!heap_->InNewSpace(obj));
+    ASSERT(obj != HEAP->raw_unchecked_the_hole_value());
+    if (obj->IsExternalAsciiString()) {
+      ExternalAsciiString* string = ExternalAsciiString::cast(obj);
+      ASSERT(String::IsAscii(string->GetChars(), string->length()));
+    }
   }
 #endif
 }
=======================================
--- /branches/bleeding_edge/src/heap.cc Tue May 15 02:54:54 2012
+++ /branches/bleeding_edge/src/heap.cc Tue May 22 05:49:20 2012
@@ -3325,6 +3325,8 @@
     isolate()->context()->mark_out_of_memory();
     return Failure::OutOfMemoryException();
   }
+
+  ASSERT(String::IsAscii(resource->data(), length));

   Map* map = external_ascii_string_map();
   Object* result;
@@ -4490,6 +4492,16 @@
   String::cast(result)->set_length(length);
   String::cast(result)->set_hash_field(String::kEmptyHashField);
   ASSERT_EQ(size, HeapObject::cast(result)->Size());
+
+#ifdef DEBUG
+  if (FLAG_verify_heap) {
+ // Initialize string's content to ensure ASCII-ness (character range 0-127)
+    // as required when verifying the heap.
+    char* dest = SeqAsciiString::cast(result)->GetChars();
+    memset(dest, 0x0F, length * kCharSize);
+  }
+#endif  // DEBUG
+
   return result;
 }

=======================================
--- /branches/bleeding_edge/src/objects-debug.cc        Tue May 15 08:45:38 2012
+++ /branches/bleeding_edge/src/objects-debug.cc        Tue May 22 05:49:20 2012
@@ -458,8 +458,15 @@
     ConsString::cast(this)->ConsStringVerify();
   } else if (IsSlicedString()) {
     SlicedString::cast(this)->SlicedStringVerify();
+  } else if (IsSeqAsciiString()) {
+    SeqAsciiString::cast(this)->SeqAsciiStringVerify();
   }
 }
+
+
+void SeqAsciiString::SeqAsciiStringVerify() {
+  CHECK(String::IsAscii(GetChars(), length()));
+}


 void ConsString::ConsStringVerify() {
=======================================
--- /branches/bleeding_edge/src/objects.h       Wed May 16 04:07:54 2012
+++ /branches/bleeding_edge/src/objects.h       Tue May 22 05:49:20 2012
@@ -7242,6 +7242,10 @@
                                                       unsigned* offset,
                                                       unsigned chars);

+#ifdef DEBUG
+  void SeqAsciiStringVerify();
+#endif
+
  private:
   DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString);
 };

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to