JavaScriptCore:
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Mar 2006 08:30:57 +0000 (08:30 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Mar 2006 08:30:57 +0000 (08:30 +0000)
        Reviewed by Anders.

        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=7655
          unwanted output while running layout tests

        * kjs/lexer.cpp: (Lexer::lex): Turn off the "yylex: ERROR" message.
        * kjs/regexp.cpp: (KJS::RegExp::RegExp): Remove the code to log errors from PCRE
        to standard output. I think we should arrange for the error text to be in JavaScript
        exceptions instead at some point.
        * kxmlcore/Vector.h: Add a check for overflow so that we'll abort if we pass a
        too-large size rather than allocating a buffer smaller than requested.

WebCore:

        Reviewed by Anders.

        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=7655
          unwanted output while running layout tests

        * khtml/xsl/xsl_stylesheetimpl.cpp: (WebCore::XSLStyleSheetImpl::parseString):
        Pass XML_PARSE_NOERROR and XML_PARSE_NOWARNING. We don't want errors and warnings
        to be logged to stdout or stderr. If we later decide we want the error messages,
        then we should do the additional work to put them into the web page or the
        console (along with the JavaScript errors).

        * platform/ArrayImpl.cpp: (WebCore::ArrayImpl::resize): Add a preflight to protect
        against integer overflow due to large array size. Noticed this while looking into
        the malloc error message.

WebKit:

        Reviewed by Anders.

        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=7655
          unwanted output while running layout tests

        * WebView/WebDataSourcePrivate.h:
        * WebView/WebDataSource.m:
        (-[WebDataSource _setRepresentation:]): Clear the flag that records whether we've sent
        all the data to the representation or not; need this to prevent telling the same representation
        both that we've succeeded and then later that we've failed.
        (-[WebDataSource _setMainDocumentError:]): Don't send an error if representationFinishedLoading
        is already YES. Set representationFinishedLoading.
        (-[WebDataSource _finishedLoading]): Set representationFinishedLoading.
        (-[WebDataSource _setupForReplaceByMIMEType:]): Ditto.

WebKitTools:

        Reviewed by Anders.

        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=7655
          unwanted output while running layout tests

        * DumpRenderTree/DumpRenderTree.m:
        (checkedMalloc): Added.
        (checkedRealloc): Added.
        (makeLargeMallocFailSilently): Added.
        (main): Call makeLargeMallocFailSilently.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@13203 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
JavaScriptCore/ChangeLog
JavaScriptCore/kjs/lexer.cpp
JavaScriptCore/kjs/regexp.cpp
JavaScriptCore/kxmlcore/Vector.h
WebCore/ChangeLog
WebCore/khtml/xsl/xsl_stylesheetimpl.cpp
WebCore/platform/ArrayImpl.cpp
WebKit/ChangeLog
WebKit/WebView/WebDataSource.m
WebKit/WebView/WebDataSourcePrivate.h
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/DumpRenderTree.m

index 1f69beff1c0b46ffcb04f2bbf9a378fe5e888be4..ad92c4fad677b4180b4398b0297e57f44bbf12f0 100644 (file)
@@ -1,3 +1,17 @@
+2006-03-07  Darin Adler  <darin@apple.com>
+
+        Reviewed by Anders.
+
+        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=7655
+          unwanted output while running layout tests
+
+        * kjs/lexer.cpp: (Lexer::lex): Turn off the "yylex: ERROR" message.
+        * kjs/regexp.cpp: (KJS::RegExp::RegExp): Remove the code to log errors from PCRE
+        to standard output. I think we should arrange for the error text to be in JavaScript
+        exceptions instead at some point.
+        * kxmlcore/Vector.h: Add a check for overflow so that we'll abort if we pass a
+        too-large size rather than allocating a buffer smaller than requested.
+
 2006-03-06  David Carson <dacarson@gmail.com>
 
         Reviewed by Darin, landed by ap.
index 6a2ea072f2e686a9c385ca7d856774015d2b1c66..989956cf1042df877a98f62d4975ca2d9691506a 100644 (file)
@@ -556,7 +556,9 @@ int Lexer::lex()
     token = NUMBER;
     break;
   case Bad:
+#ifdef KJS_DEBUG_LEX
     fprintf(stderr, "yylex: ERROR.\n");
+#endif
     error = true;
     return -1;
   default:
index bb8ce8f0b56d33e66eb9e62d9bb6663096fe19a6..ae3010a03a1953ff3b9c78514cacaca26e3b4f19 100644 (file)
@@ -48,12 +48,8 @@ RegExp::RegExp(const UString &p, int flags)
   char null(0);
   nullTerminated.append(null);
   _regex = pcre_compile(reinterpret_cast<const uint16_t *>(nullTerminated.data()), options, &errorMessage, &errorOffset, NULL);
-  if (!_regex) {
-#ifndef NDEBUG
-    fprintf(stderr, "KJS: pcre_compile() failed with '%s'\n", errorMessage);
-#endif
+  if (!_regex)
     return;
-  }
 
 #ifdef PCRE_INFO_CAPTURECOUNT
   // Get number of subpatterns that will be returned.
index 594cfeb5565b9230d4f41675b4a82dc486bf7daf..2845ee441f256c4890d5ba83407f05974eec6b90 100644 (file)
 #define KXMLCORE_VECTOR_H
 
 #include "Assertions.h"
+#include "VectorTraits.h"
+#include <limits>
 #include <stdlib.h>
 #include <utility>
-#include "VectorTraits.h"
 
 namespace KXMLCore {
 
@@ -241,6 +242,8 @@ namespace KXMLCore {
         {
             ASSERT(newCapacity >= m_capacity);
             m_capacity = newCapacity;
+            if (newCapacity > std::numeric_limits<size_t>::max() / sizeof(T))
+                abort();
             m_buffer = reinterpret_cast<T*>(fastMalloc(newCapacity * sizeof(T)));
         }
 
index 8160bacc1a048353712b69b4b04fda3c398ed8ce..2e00c9ffe941052a9b6b15968222b596f71fa796 100644 (file)
@@ -1,3 +1,20 @@
+2006-03-07  Darin Adler  <darin@apple.com>
+
+        Reviewed by Anders.
+
+        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=7655
+          unwanted output while running layout tests
+
+        * khtml/xsl/xsl_stylesheetimpl.cpp: (WebCore::XSLStyleSheetImpl::parseString):
+        Pass XML_PARSE_NOERROR and XML_PARSE_NOWARNING. We don't want errors and warnings
+        to be logged to stdout or stderr. If we later decide we want the error messages,
+        then we should do the additional work to put them into the web page or the
+        console (along with the JavaScript errors).
+
+        * platform/ArrayImpl.cpp: (WebCore::ArrayImpl::resize): Add a preflight to protect
+        against integer overflow due to large array size. Noticed this while looking into
+        the malloc error message.
+
 2006-03-07  Darin Adler  <darin@apple.com>
 
         Reviewed by Adele.
index e4e0cd6b1b9126c3e2bf66a2829086eebe69c46e..6691b01ca78c8d5c2da232f6563089f6cfdfebb3 100644 (file)
@@ -127,11 +127,10 @@ bool XSLStyleSheetImpl::parseString(const DOMString &string, bool strict)
     if (!m_stylesheetDocTaken)
         xmlFreeDoc(m_stylesheetDoc);
     m_stylesheetDocTaken = false;
-    m_stylesheetDoc = xmlReadMemory(reinterpret_cast<const char *>(string.unicode()),
-                                    string.length() * sizeof(QChar),
-                                    m_ownerDocument->URL().ascii(),
-                                    BOMHighByte == 0xFF ? "UTF-16LE" : "UTF-16BE", 
-                                    XML_PARSE_NOCDATA|XML_PARSE_DTDATTR|XML_PARSE_NOENT);
+    m_stylesheetDoc = xmlReadMemory(reinterpret_cast<const char *>(string.unicode()), string.length() * sizeof(QChar),
+        m_ownerDocument->URL().ascii(),
+        BOMHighByte == 0xFF ? "UTF-16LE" : "UTF-16BE", 
+        XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NOCDATA);
     loadChildSheets();
     setLoaderForLibXMLCallbacks(0);
     return m_stylesheetDoc;
index 6ea2e88e08013ed64e25d1c3baaa515773144ea3..07154c93cf99ebac2d0db0a32d06155670fe866e 100644 (file)
 
 #include "config.h"
 #include "ArrayImpl.h"
-#include <stddef.h>
 
+#include <limits>
 #include <new>
+#include <stddef.h>
 #include <string.h>
 
-#define        MIN(a,b) (((a)<(b))?(a):(b))
-
-using std::nothrow;
-
 namespace WebCore {
 
 ArrayImpl::ArrayPrivate::ArrayPrivate(size_t pItemSize, size_t pNumItems) : 
@@ -80,12 +77,14 @@ bool ArrayImpl::resize(size_t newSize)
         char *newData;
         
        if (newSize != 0) {
+            size_t maxSize = std::numeric_limits<size_t>::max() / d->itemSize;
+            if (newSize > maxSize)
+                return false;
            newData = static_cast<char *>(fastRealloc(d->data, newSize * d->itemSize));
-           if (newData == NULL) {
+           if (!newData)
                return false;
-           }
        } else {
-           newData = NULL;
+           newData = 0;
             fastFree(d->data);
        }
 
index 461a36876858b0adb79b36c057442ecdfe42d8a9..a5c4eb060e6f4efabf38e4e656cbdaf442df15d0 100644 (file)
@@ -1,3 +1,20 @@
+2006-03-07  Darin Adler  <darin@apple.com>
+
+        Reviewed by Anders.
+
+        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=7655
+          unwanted output while running layout tests
+
+        * WebView/WebDataSourcePrivate.h:
+        * WebView/WebDataSource.m:
+        (-[WebDataSource _setRepresentation:]): Clear the flag that records whether we've sent
+        all the data to the representation or not; need this to prevent telling the same representation
+        both that we've succeeded and then later that we've failed.
+        (-[WebDataSource _setMainDocumentError:]): Don't send an error if representationFinishedLoading
+        is already YES. Set representationFinishedLoading.
+        (-[WebDataSource _finishedLoading]): Set representationFinishedLoading.
+        (-[WebDataSource _setupForReplaceByMIMEType:]): Ditto.
+
 2006-03-06  Tim Omernick  <timo@apple.com>
 
         Reviewed by Kevin Decker.
index 2e6065e1a906e1a250c258823c95adb970b0e752..a178668da531931f18de4893b0be71b58094d76b 100644 (file)
 {
     [_private->representation release];
     _private->representation = [representation retain];
+    _private->representationFinishedLoading = NO;
 }
 
 - (void)_setLoading:(BOOL)loading
     [_private->mainDocumentError release];
     _private->mainDocumentError = error;
 
-    [[self representation] receivedError:error withDataSource:self];
+    if (!_private->representationFinishedLoading) {
+        _private->representationFinishedLoading = YES;
+        [[self representation] receivedError:error withDataSource:self];
+    }
 }
 
 - (void)_clearErrors
@@ -650,9 +654,8 @@ static inline void addTypesFromClass(NSMutableDictionary *allTypes, Class class,
     _private->gotFirstByte = YES;
     [self _commitIfReady];
 
+    _private->representationFinishedLoading = YES;
     [[self representation] finishedLoadingWithDataSource:self];
-    // Since we've sent openURL to the bridge, it's important to send end too, so that WebCore
-    // can realize that the load is completed.
     [[self _bridge] end];
 }
 
@@ -916,6 +919,7 @@ static inline void addTypesFromClass(NSMutableDictionary *allTypes, Class class,
         [self _commitLoadWithData:[self data]];
     }
     
+    _private->representationFinishedLoading = YES;
     [[self representation] finishedLoadingWithDataSource:self];
     [[self _bridge] end];
 
index 5f82e25c9bc783449c43a99dcfacb11088e07666..3f3ab2bcf13a21bd8c92186a1d15b16e03693570 100644 (file)
@@ -97,6 +97,7 @@
 
     BOOL gotFirstByte; // got first byte
     BOOL committed; // This data source has been committed
+    BOOL representationFinishedLoading;
 
     BOOL defersCallbacks;
 
index c68176c8a1d149beac6cbfc6fdbcc277e9e85c90..a1407d63d62197845ff4318d08392c0dfa364916 100644 (file)
@@ -1,3 +1,16 @@
+2006-03-07  Darin Adler  <darin@apple.com>
+
+        Reviewed by Anders.
+
+        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=7655
+          unwanted output while running layout tests
+
+        * DumpRenderTree/DumpRenderTree.m:
+        (checkedMalloc): Added.
+        (checkedRealloc): Added.
+        (makeLargeMallocFailSilently): Added.
+        (main): Call makeLargeMallocFailSilently.
+
 2006-03-06  Darin Adler  <darin@apple.com>
 
         * Scripts/do-webcore-rename: Add some more planned renaming.
index 758fe51e73e697c92f02301d0edb5e9b1c19b328..4463d69f9973e953c28ea8b7bc41f019e9ad97a0 100644 (file)
@@ -46,6 +46,7 @@
 #import <CommonCrypto/CommonDigest.h>               // for MD5 functions
 
 #import <getopt.h>
+#import <malloc/malloc.h>
 
 #import "TextInputController.h"
 #import "NavigationController.h"
@@ -162,6 +163,32 @@ static void setDefaultColorProfileToRGB(void)
     CFRelease(previousProfileName);
 }
 
+static void* (*savedMalloc)(malloc_zone_t*, size_t);
+static void* (*savedRealloc)(malloc_zone_t*, void*, size_t);
+
+static void* checkedMalloc(malloc_zone_t* zone, size_t size)
+{
+    if (size >= 0x10000000)
+        return 0;
+    return savedMalloc(zone, size);
+}
+
+static void* checkedRealloc(malloc_zone_t* zone, void* ptr, size_t size)
+{
+    if (size >= 0x10000000)
+        return 0;
+    return savedRealloc(zone, ptr, size);
+}
+
+static void makeLargeMallocFailSilently(void)
+{
+    malloc_zone_t* zone = malloc_default_zone();
+    savedMalloc = zone->malloc;
+    savedRealloc = zone->realloc;
+    zone->malloc = checkedMalloc;
+    zone->realloc = checkedRealloc;
+}
+
 int main(int argc, const char *argv[])
 {
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@@ -249,6 +276,8 @@ int main(int argc, const char *argv[])
     [window setAutodisplay:NO];
 
     [webView setContinuousSpellCheckingEnabled:YES];
+
+    makeLargeMallocFailSilently();
     
     // For reasons that are not entirely clear, the following pair of calls makes WebView handle its
     // dynamic scrollbars properly. Without it, every frame will always have scrollbars.