A better fix for http://www.crbug.com/2044: crash

on large <canvas> elements.  We disable the __debugbreak
only when skia tells us it is prepared to correctly 
handle a failed (NULL) malloc().  It does this
by calling sk_malloc_flags() without SK_MALLOC_THROW.

Note that, since the switch to tcmalloc, the new_handler
was not getting called at all (since tcmalloc doesn't 
support it yet), so this crash is currently unreproducible
in trunk.  In order to test this change, I reverted the 
tcmalloc change in my client.  This is not the case in the 
stable branch, since it doesn't use tcmalloc, so this change 
is still needed there.  (It will also be needed in trunk 
again once mbelshe's re-implementation of the new_handler
is in).

BUG=http://www.crbug.com/2044
Review URL: http://codereview.chromium.org/100163

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14891 0039d316-1c4b-4281-b951-d872f2087c98
parent 313b4919
...@@ -4,5 +4,6 @@ include_rules = [ ...@@ -4,5 +4,6 @@ include_rules = [
"+chrome/installer", "+chrome/installer",
"+chrome/personalization", "+chrome/personalization",
"+sandbox", "+sandbox",
"+skia/include/corecg",
"+tools/memory_watcher", "+tools/memory_watcher",
] ]
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
#include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h" #include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h"
#endif #endif
#include "skia/include/corecg/SkTypes.h"
extern int BrowserMain(const MainFunctionParams&); extern int BrowserMain(const MainFunctionParams&);
extern int RendererMain(const MainFunctionParams&); extern int RendererMain(const MainFunctionParams&);
...@@ -110,6 +111,12 @@ void PureCall() { ...@@ -110,6 +111,12 @@ void PureCall() {
} }
void OnNoMemory() { void OnNoMemory() {
// Skia indicates that it can safely handle some NULL allocs by clearing
// this flag. In this case, we'll ignore the new_handler and won't crash.
if (!sk_malloc_will_throw()) {
return;
}
// Kill the process. This is important for security, since WebKit doesn't // Kill the process. This is important for security, since WebKit doesn't
// NULL-check many memory allocations. If a malloc fails, returns NULL, and // NULL-check many memory allocations. If a malloc fails, returns NULL, and
// the buffer is then used, it provides a handy mapping of memory starting at // the buffer is then used, it provides a handy mapping of memory starting at
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
// #define SK_CHECK_TAGS // enable to double-check debugging link list // #define SK_CHECK_TAGS // enable to double-check debugging link list
#endif #endif
static bool g_sk_malloc_will_throw = true;
#ifdef SK_TAG_BLOCKS #ifdef SK_TAG_BLOCKS
#include "SkThread.h" #include "SkThread.h"
...@@ -257,7 +259,13 @@ void* sk_malloc_flags(size_t size, unsigned flags) ...@@ -257,7 +259,13 @@ void* sk_malloc_flags(size_t size, unsigned flags)
size += sizeof(SkBlockHeader); size += sizeof(SkBlockHeader);
#endif #endif
if (!(flags & SK_MALLOC_THROW)) {
g_sk_malloc_will_throw = false;
}
void* p = malloc(size); void* p = malloc(size);
if (!(flags & SK_MALLOC_THROW)) {
g_sk_malloc_will_throw = true;
}
if (p == NULL) if (p == NULL)
{ {
if (flags & SK_MALLOC_THROW) if (flags & SK_MALLOC_THROW)
...@@ -278,3 +286,7 @@ void* sk_malloc_flags(size_t size, unsigned flags) ...@@ -278,3 +286,7 @@ void* sk_malloc_flags(size_t size, unsigned flags)
return p; return p;
} }
bool sk_malloc_will_throw()
{
return g_sk_malloc_will_throw;
}
...@@ -65,6 +65,11 @@ extern void* sk_realloc_throw(void* buffer, size_t size); ...@@ -65,6 +65,11 @@ extern void* sk_realloc_throw(void* buffer, size_t size);
*/ */
extern void sk_free(void*); extern void sk_free(void*);
/** Returns whether sk_malloc() will currently throw. Only false during
a call to sk_malloc_flags() with SK_MALLOC_THROW not set. This is
useful to mallocs that would otherwise abort on NULL themselves.
false indicates that skia will safely handle NULL checking. **/
extern bool sk_malloc_will_throw();
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
#define SK_INIT_TO_AVOID_WARNING = 0 #define SK_INIT_TO_AVOID_WARNING = 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment