<?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>260908</bug_id>
          
          <creation_ts>2023-08-30 09:21:58 -0700</creation_ts>
          <short_desc>[JSC][32 bit] Crash in DFG when compiling TypedArray intrinsic getter with conflicting value profile</short_desc>
          <delta_ts>2023-08-31 11:17:18 -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 Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <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="Joseph Griego">joseph.j.griego</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1974467</commentid>
    <comment_count>0</comment_count>
    <who name="Joseph Griego">joseph.j.griego</who>
    <bug_when>2023-08-30 09:21:58 -0700</bug_when>
    <thetext>On 32-bit, some DFG intrinsic getters are fallible--if the SpeculatedType does not match our expectations; however, in `ByteCodeParser::handleGetById`, we seem not to handle this possibility--the following program demonstrates this problem and crashes with a segfault on armv7:

function foo(x) {
        return x.byteLength
}

var arr = new Uint8Array(42);

var bad = {};

for (var i = 0; i &lt; 1e6; i++) {
        if (null != foo(Object.create(bad))) {
                throw new Error();
        }
}

bad.byteLength = 42;

for (var i = 0; i &lt; 1e6; i++) {
        if (42 != foo(arr)) {
                throw new Error();
        }
}

and in the debugger we see:

jgriego@devbox-armhf-1:~/proj/webkit$ gdb --args _build/bin/jsc test.js                                                                                                                                                                                                                    
GNU gdb (Debian 10.1-1.7) 10.1.90.20210103-git                                                                                                                                                                                                                                             
Copyright (C) 2021 Free Software Foundation, Inc.                                                                                                                                                                                                                                          
License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;                                                                                                                                                                                                              
This is free software: you are free to change and redistribute it.                                                                                                                                                                                                                         
There is NO WARRANTY, to the extent permitted by law.                                                                                                                                                                                                                                      
Type &quot;show copying&quot; and &quot;show warranty&quot; for details.                                                                                                                                                                                                                                       
This GDB was configured as &quot;arm-linux-gnueabihf&quot;.                                                                                                                                                                                                                                          
Type &quot;show configuration&quot; for configuration details.                                                                                                                                                                                                                                       
For bug reporting instructions, please see:                                                                                                                                                                                                                                                
&lt;https://www.gnu.org/software/gdb/bugs/&gt;.                                                                                                                                                                                                                                                  
Find the GDB manual and other documentation resources online at:                                                                                                                                                                                                                           
    &lt;http://www.gnu.org/software/gdb/documentation/&gt;.                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                           
For help, type &quot;help&quot;.                                                                                                                                                                                                                                                                     
Type &quot;apropos word&quot; to search for commands related to &quot;word&quot;...                                                                                                                                                                                                                            
Reading symbols from _build/bin/jsc...                                                                                                                                                                                                                                                     
(gdb) r                                                                                                                                                                                                                                                                                    
Starting program: /home/igalia/jgriego/proj/webkit/_build/bin/jsc test.js                                                                                                                                                                                                                  
[Thread debugging using libthread_db enabled]                                                                                                                                                                                                                                              
Using host libthread_db library &quot;/lib/arm-linux-gnueabihf/libthread_db.so.1&quot;.                                                                                                                                                                                                              
[New Thread 0xf37ff440 (LWP 3086765)]                                                                                                                                                                                                                                                      
[New Thread 0xebdff440 (LWP 3086792)]
[New Thread 0xeb5fe440 (LWP 3086793)]
[New Thread 0xeadfd440 (LWP 3086794)]
[New Thread 0xea5fc440 (LWP 3086795)]
[New Thread 0xe9dfb440 (LWP 3086796)]
[New Thread 0xe95fa440 (LWP 3086797)]
[New Thread 0xe8df9440 (LWP 3086798)]

Thread 1 &quot;jsc&quot; received signal SIGSEGV, Segmentation fault.
0xf5c67fc8 in WTF::Vector&lt;JSC::CallVariant, 1u, WTF::CrashOnOverflow, 16u, WTF::FastMalloc&gt;::size (this=0x0) at /home/igalia/jgriego/proj/webkit/_build/WTF/Headers/wtf/Vector.h:764
764         size_t size() const { return m_size; }
(gdb) bt
#0  0xf5c67fc8 in WTF::Vector&lt;JSC::CallVariant, 1u, WTF::CrashOnOverflow, 16u, WTF::FastMalloc&gt;::size (this=0x0) at /home/igalia/jgriego/proj/webkit/_build/WTF/Headers/wtf/Vector.h:764
#1  0xf5c67f58 in WTF::Vector&lt;JSC::CallVariant, 1u, WTF::CrashOnOverflow, 16u, WTF::FastMalloc&gt;::Vector (this=0xfffe9a2c, other=...) at /home/igalia/jgriego/proj/webkit/_build/WTF/Headers/wtf/Vector.h:964
#2  0xf5c64e38 in JSC::CallLinkStatus::CallLinkStatus (this=0xfffe9a2c) at /home/igalia/jgriego/proj/webkit/Source/JavaScriptCore/bytecode/CallLinkStatus.h:44
#3  0xf5e5306a in JSC::DFG::ByteCodeParser::handleGetById (this=0xfffed32c, destination=..., prediction=2207613190144, base=0xf2e81ba0, identifier=..., identifierNumber=0, getByStatus=..., type=JSC::AccessType::GetById, osrExitIndex=...)
    at /home/igalia/jgriego/proj/webkit/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:4818
#4  0xf5ed5d56 in JSC::DFG::ByteCodeParser::parseGetById&lt;JSC::OpGetById&gt; (this=0xfffed32c, currentInstruction=0xf2eb44b7) at /home/igalia/jgriego/proj/webkit/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:5374
#5  0xf5e6061a in JSC::DFG::ByteCodeParser::parseBlock (this=0xfffed32c, limit=14) at /home/igalia/jgriego/proj/webkit/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:6580
#6  0xf5e741a6 in JSC::DFG::ByteCodeParser::parseCodeBlock (this=0xfffed32c) at /home/igalia/jgriego/proj/webkit/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:8844
#7  0xf5e746d6 in JSC::DFG::ByteCodeParser::parse (this=0xfffed32c) at /home/igalia/jgriego/proj/webkit/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:9046
#8  0xf5e75266 in JSC::DFG::parse (graph=...) at /home/igalia/jgriego/proj/webkit/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:9182
#9  0xf60ae650 in JSC::DFG::Plan::compileInThreadImpl (this=0xf2ea12f0) at /home/igalia/jgriego/proj/webkit/Source/JavaScriptCore/dfg/DFGPlan.cpp:201
#10 0xf66829a8 in JSC::JITPlan::compileInThread (this=0xf2ea12f0, thread=0x0) at /home/igalia/jgriego/proj/webkit/Source/JavaScriptCore/jit/JITPlan.cpp:172
#11 0xf6720b00 in JSC::JITWorklist::enqueue (this=0xf2ec5288, plan=...) at /home/igalia/jgriego/proj/webkit/Source/JavaScriptCore/jit/JITWorklist.cpp:84
#12 0xf5fc08e0 in JSC::DFG::compileImpl (vm=..., codeBlock=0xf06afdc0, profiledDFGCodeBlock=0x0, mode=JSC::JITCompilationMode::DFG, osrEntryBytecodeIndex=..., mustHandleValues=..., callback=...) at /home/igalia/jgriego/proj/webkit/Source/JavaScriptCore/dfg/DFGDriver.cpp:90
#13 0xf5fc09ac in JSC::DFG::compile (vm=..., codeBlock=0xf06afdc0, profiledDFGCodeBlock=0x0, mode=JSC::JITCompilationMode::DFG, osrEntryBytecodeIndex=..., mustHandleValues=..., callback=...) at /home/igalia/jgriego/proj/webkit/Source/JavaScriptCore/dfg/DFGDriver.cpp:106
#14 0xf667a7d6 in JSC::operationOptimize (vmPointer=0xf0cf5000, bytecodeIndexBits=0) at /home/igalia/jgriego/proj/webkit/Source/JavaScriptCore/jit/JITOperations.cpp:2028
#15 0xf0dff87a in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) frame 3
#3  0xf5e5306a in JSC::DFG::ByteCodeParser::handleGetById (this=0xfffed32c, destination=..., prediction=2207613190144, base=0xf2e81ba0, identifier=..., identifierNumber=0, getByStatus=..., type=JSC::AccessType::GetById, osrExitIndex=...)
    at /home/igalia/jgriego/proj/webkit/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:4818
4818            getter, numberOfParameters - 1, registerOffset, *variant.callLinkStatus(), prediction);
(gdb) p variant.callLinkStatus()
$1 = (JSC::CallLinkStatus *) 0x0
(gdb) p/x prediction
$2 = 0x20200000000
(gdb) p variant.intrinsic()
[Thread 0xebdff440 (LWP 3086792) exited]
[Thread 0xea5fc440 (LWP 3086795) exited]
$3 = JSC::TypedArrayByteLengthIntrinsic

* * *

To fix, I propose we add code to generate an ordinary GetById node if the code generation for the intrinsic fails; I&apos;ll send a patch to this effect shortly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1974486</commentid>
    <comment_count>1</comment_count>
    <who name="Joseph Griego">joseph.j.griego</who>
    <bug_when>2023-08-30 10:34:51 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/17232</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1974774</commentid>
    <comment_count>2</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-08-31 11:16:50 -0700</bug_when>
    <thetext>Committed 267511@main (7a9106c7a56f): &lt;https://commits.webkit.org/267511@main&gt;

Reviewed commits have been landed. Closing PR #17232 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1974775</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-08-31 11:17:18 -0700</bug_when>
    <thetext>&lt;rdar://problem/114775615&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>