<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>181934</bug_id>
          
          <creation_ts>2018-01-22 07:55:24 -0800</creation_ts>
          <short_desc>WebKitGTK/JavaScriptCore segfault with CrashOnOverflow</short_desc>
          <delta_ts>2018-03-30 07:48:40 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>WebKit Local Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>183894</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Suyoung Lee">sevendays37</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>rmorisset</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1391634</commentid>
    <comment_count>0</comment_count>
    <who name="Suyoung Lee">sevendays37</who>
    <bug_when>2018-01-22 07:55:24 -0800</bug_when>
    <thetext>Crashes on the latest version of WebKitGTK/JavaScriptCore (both on debug/release build).

Here is the input code.

function foo(v1, v2)
{
  throw JSON.stringify(v1) + JSON.stringify(v2);
}

function func_0() {
  try {
    foo(func_0(func_0), 1);
  } catch (func_0) {
    return func_0;
  }
}

func_0();

It seems that this code causes integer overflow at StringBuilderJSON.cpp:85
85     maximumCapacityRequired += 2 + stringLength * 6;


(gdb) r
Starting program: /data/WebKit/WebKitBuild/Debug/bin/jsc test.js
[Thread debugging using libthread_db enabled]
Using host libthread_db library &quot;/lib/x86_64-linux-gnu/libthread_db.so.1&quot;.
[New Thread 0x7ffff0cef700 (LWP 15461)]
[New Thread 0x7fffaf6ff700 (LWP 15462)]
[New Thread 0x7fffaeefe700 (LWP 15463)]
[New Thread 0x7fffad9ff700 (LWP 15464)]
[New Thread 0x7fffad1fe700 (LWP 15465)]
[New Thread 0x7fffac9fd700 (LWP 15466)]
[New Thread 0x7fffa7fff700 (LWP 15467)]
[New Thread 0x7fffa77fe700 (LWP 15468)]
[New Thread 0x7fffa6ffd700 (LWP 15469)]
[New Thread 0x7fffa67fc700 (LWP 15470)]
1   0x7ffff6d6a123 WTFCrash
2   0x46764e WTF::CrashOnOverflow::hasOverflowed() const
3   0x467645 WTF::CrashOnOverflow::crash()
4   0x7ffff5f5ba90 JSC::CompleteSubspace* JSC::JSCell::subspaceFor&lt;JSC::JSSet&gt;(JSC::VM&amp;)
5   0x7ffff6dc29fc
6   0x7ffff6dc250f
7   0x7ffff6dc21d5 WTF::StringBuilder::appendQuotedJSONString(WTF::String const&amp;)
8   0x7ffff6a3e4b8 JSC::Stringifier::appendStringifiedValue(WTF::StringBuilder&amp;, JSC::JSValue, JSC::Stringifier::Holder const&amp;, JSC::PropertyNameForFunctionCall const&amp;)
9   0x7ffff6a3ddf9 JSC::Stringifier::stringify(JSC::JSValue)
10  0x7ffff6a40c1e JSC::JSONProtoFuncStringify(JSC::ExecState*)
11  0x7fffb02ff178

Thread 1 &quot;jsc&quot; received signal SIGSEGV, Segmentation fault.
0x00007ffff6d6a128 in WTFCrash () at ../../Source/WTF/wtf/Assertions.cpp:272
272	    *(int *)(uintptr_t)0xbbadbeef = 0;
(gdb) bt
#0  0x00007ffff6d6a128 in WTFCrash () at ../../Source/WTF/wtf/Assertions.cpp:272
#1  0x000000000046764e in WTF::CrashOnOverflow::crash () at ../../Source/WTF/wtf/CheckedArithmetic.h:85
#2  0x0000000000467645 in WTF::CrashOnOverflow::overflowed () at ../../Source/WTF/wtf/CheckedArithmetic.h:78
#3  0x00007ffff5f5ba90 in WTF::Checked&lt;unsigned int, WTF::CrashOnOverflow&gt;::Checked (this=0x7fffffc1e310)
    at ../../Source/WTF/wtf/CheckedArithmetic.h:462
#4  0x00007ffff6dc29fc in WTF::operator*&lt;unsigned int, int, WTF::CrashOnOverflow&gt; (lhs=..., rhs=...)
    at ../../Source/WTF/wtf/CheckedArithmetic.h:745
#5  0x00007ffff6dc250f in WTF::operator*&lt;unsigned int, int, WTF::CrashOnOverflow&gt; (lhs=..., rhs=6)
    at ../../Source/WTF/wtf/CheckedArithmetic.h:761
#6  0x00007ffff6dc21d5 in WTF::StringBuilder::appendQuotedJSONString (this=0x7fffffc1e5b0, string=...)
    at ../../Source/WTF/wtf/text/StringBuilderJSON.cpp:85
#7  0x00007ffff6a3e4b8 in JSC::Stringifier::appendStringifiedValue (this=0x7fffffc1e6c0, builder=..., value=..., 
    holder=..., propertyName=...) at ../../Source/JavaScriptCore/runtime/JSONObject.cpp:360
#8  0x00007ffff6a3ddf9 in JSC::Stringifier::stringify (this=0x7fffffc1e6c0, value=...)
    at ../../Source/JavaScriptCore/runtime/JSONObject.cpp:275
#9  0x00007ffff6a40c1e in JSC::JSONProtoFuncStringify (exec=0x7fffffc1e9f0)
    at ../../Source/JavaScriptCore/runtime/JSONObject.cpp:841
#10 0x00007fffb02ff178 in ?? ()
#11 0x00007fffffc1ea70 in ?? ()
#12 0x00007ffff67b5a47 in llint_entry () at ../../Source/JavaScriptCore/runtime/Butterfly.h:52
Backtrace stopped: frame did not save the PC</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1410592</commentid>
    <comment_count>1</comment_count>
    <who name="Robin Morisset">rmorisset</who>
    <bug_when>2018-03-30 07:48:40 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 183894 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>