<?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>197191</bug_id>
          
          <creation_ts>2019-04-23 01:44:20 -0700</creation_ts>
          <short_desc>Segmentation fault in JSC::JSGenericTypedArrayView&lt;JSC::Int32Adaptor&gt;::sort with concurrent write access on SharedArrayBuffer</short_desc>
          <delta_ts>2020-11-04 00:29:22 -0800</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>212069</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="André Bargull">andre.bargull</reporter>
          <assigned_to name="Yusuke Suzuki">ysuzuki</assigned_to>
          <cc>anthony</cc>
    
    <cc>bilgorajskim</cc>
    
    <cc>fpizlo</cc>
    
    <cc>keith_miller</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1529542</commentid>
    <comment_count>0</comment_count>
    <who name="André Bargull">andre.bargull</who>
    <bug_when>2019-04-23 01:44:20 -0700</bug_when>
    <thetext>SVN rev: r244537 (with ENABLE_SHARED_ARRAY_BUFFER = 1)


Test case:
```
$262.agent.waitUntil = function(typedArray, index, expected) {
  var agents = 0;
  while ((agents = Atomics.load(typedArray, index)) !== expected) {
    /* nothing */
  }
};

const ITERATIONS = 10000;
const RUNNING = 0;

const i32a = new Int32Array(
  new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 100000)
);

$262.agent.start(`
  $262.agent.receiveBroadcast(function(sab) {
    const i32a = new Int32Array(sab);
    Atomics.add(i32a, ${RUNNING}, 1);
    
    for (var j = 1; j &lt; ${ITERATIONS}; ++j) {
        for (var i = 0; i &lt; i32a.length; ++i) {
            i32a[i] = j;
        }
    }
    
    $262.agent.report(&quot;done&quot;);
    $262.agent.leaving();
  });
`);

$262.agent.broadcast(i32a.buffer);
$262.agent.waitUntil(i32a, RUNNING, 1);

for (var i = 0; i &lt; ITERATIONS; ++i) {
    i32a.sort();
}

print(&quot;report: &quot;, $262.agent.getReport());
```


Crashes with seg-fault:
```
Thread 1 &quot;jsc-debug&quot; received signal SIGSEGV, Segmentation fault.
0x00007ffff6353454 in __gnu_cxx::__ops::_Iter_less_iter::operator()&lt;int*, int*&gt; (this=0x7fffffffb4b8, __it1=0x7ff000000000, __it2=0x7fe80b660000)
    at /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/predefined_ops.h:43
43            { return *__it1 &lt; *__it2; }
```

Stacktrace:
```
#0  0x00007ffff6353454 in __gnu_cxx::__ops::_Iter_less_iter::operator()&lt;int*, int*&gt; (this=0x7fffffffb4b8, __it1=0x7ff000000000, __it2=0x7fe80b660000)
    at /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/predefined_ops.h:43
#1  0x00007ffff635392a in std::__unguarded_partition&lt;int*, __gnu_cxx::__ops::_Iter_less_iter&gt; (__first=0x7ff000000000, __last=0x7fe80b66d008, __pivot=0x7fe80b660000, __comp=...)
    at /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/stl_algo.h:1902
#2  0x00007ffff6353260 in std::__unguarded_partition_pivot&lt;int*, __gnu_cxx::__ops::_Iter_less_iter&gt; (__first=0x7fe80b660000, __last=0x7fe80b678618, __comp=...)
    at /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/stl_algo.h:1923
#3  0x00007ffff6353107 in std::__introsort_loop&lt;int*, long, __gnu_cxx::__ops::_Iter_less_iter&gt; (__first=0x7fe80b660000, __last=0x7fe80b678618, __depth_limit=29, __comp=...)
    at /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/stl_algo.h:1953
#4  0x00007ffff6353089 in std::__sort&lt;int*, __gnu_cxx::__ops::_Iter_less_iter&gt; (__first=0x7fe80b660000, __last=0x7fe80b6c1a80, __comp=...)
    at /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/stl_algo.h:1968
#5  0x00007ffff6350b22 in std::sort&lt;int*&gt; (__first=0x7fe80b660000, __last=0x7fe80b6c1a80) at /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/stl_algo.h:4834
#6  0x00007ffff69bfc45 in JSC::JSGenericTypedArrayView&lt;JSC::Int32Adaptor&gt;::sort (this=0x7fffafae83a0) at ../../Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h:206
#7  0x00007ffff699c3a8 in JSC::genericTypedArrayViewPrivateFuncSort&lt;JSC::JSGenericTypedArrayView&lt;JSC::Int32Adaptor&gt; &gt; (vm=..., exec=0x7fffffffb7e0)
    at ../../Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h:413
#8  0x00007ffff6996e93 in JSC::typedArrayViewPrivateFuncSort (exec=0x7fffffffb7e0) at ../../Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.cpp:105
...
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1529593</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2019-04-23 08:31:58 -0700</bug_when>
    <thetext>&lt;rdar://problem/50130547&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1641407</commentid>
    <comment_count>2</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2020-04-14 09:34:14 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 197634 ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1641409</commentid>
    <comment_count>3</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2020-04-14 09:34:33 -0700</bug_when>
    <thetext>Thanks for your report! This is fixed in bug 197634 :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1641410</commentid>
    <comment_count>4</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2020-04-14 09:35:45 -0700</bug_when>
    <thetext>Ah, no. Wrong bug close.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1704337</commentid>
    <comment_count>5</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2020-11-03 23:38:15 -0800</bug_when>
    <thetext>The problem is that sort is assuming that we do not break total ordering of the already sorted values. But this is wrong in this case: shared array buffer is shared, and the other thread can modify it while sorting.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1704342</commentid>
    <comment_count>6</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2020-11-04 00:29:22 -0800</bug_when>
    <thetext>Will fix as a part of bug 212069&apos;s patch.
Thanks!

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

    </bug>

</bugzilla>