<?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>247419</bug_id>
          
          <creation_ts>2022-11-03 04:30:12 -0700</creation_ts>
          <short_desc>Nullptr dereference during forEachInIterable</short_desc>
          <delta_ts>2022-11-14 10:17:58 -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 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>P1</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>247702</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Samuel Groß">saelo</reporter>
          <assigned_to name="Justin Michaud">justin_michaud</assigned_to>
          <cc>justin_michaud</cc>
    
    <cc>mark.lam</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1910036</commentid>
    <comment_count>0</comment_count>
    <who name="Samuel Groß">saelo</who>
    <bug_when>2022-11-03 04:30:12 -0700</bug_when>
    <thetext>The following sample triggers a nullptr dereference on JSC build from latest HEAD

    function main() {
        function v1(v2,v3) {
            return v1;
        }
        Object.defineProperty(v1, &quot;done&quot;, { configurable: true, enumerable: true, get: WeakMap })
        v1.return = v1
        v1.next = v1;
        Object.defineProperty(WeakMap, Symbol.iterator, { configurable: true, value: v1 })
        const v24 = new WeakMap(WeakMap);
    }
    noDFG(main);
    noFTL(main);
    main();
    // CRASH INFO
    // ==========
    // TERMSIG: 11

Here is the backtrace from gdb:

    #0  JSC::JSCell::isString (this=0x0) at Source/JavaScriptCore/runtime/JSCellInlines.h:219
    #1  0x00007ffff544f2bd in JSC::JSCell::toBoolean (this=0x0, globalObject=0x7fffa541a068) at Source/JavaScriptCore/runtime/JSCellInlines.h:371
    #2  0x00007ffff5447d55 in JSC::JSValue::toBoolean (this=0x7fffffffc248, globalObject=0x7fffa541a068) at Source/JavaScriptCore/runtime/JSCJSValueInlines.h:935
    #3  0x00007ffff6bfffea in JSC::iteratorComplete (globalObject=0x7fffa541a068, iterResult=...) at Source/JavaScriptCore/runtime/IteratorOperations.cpp:68
    #4  0x00007ffff6c0020c in JSC::iteratorStep (globalObject=0x7fffa541a068, iterationRecord=...) at Source/JavaScriptCore/runtime/IteratorOperations.cpp:78
    #5  0x00007ffff6f8ecab in JSC::forEachInIterable&lt;JSC::constructWeakMap(JSC::JSGlobalObject*, JSC::CallFrame*)::$_4&gt;(JSC::JSGlobalObject*, JSC::JSValue, JSC::constructWeakMap(JSC::JSGlobalObject*, JSC::CallFrame*)::$_4 const&amp;) (globalObject=0x7fffa541a068, iterable=..., callback=...)
        at Source/JavaScriptCore/runtime/IteratorOperations.h:87
    #6  0x00007ffff6f8d0a5 in JSC::constructWeakMap (globalObject=0x7fffa541a068, callFrame=0x7fffffffc6e0) at Source/JavaScriptCore/runtime/WeakMapConstructor.cpp:83
    #7  0x00007fffa6a000c7 in ?? ()
    #8  0x00007fffffffc7b0 in ?? ()
    #9  0x00007ffff5333fbb in js_trampoline_op_construct () from WebKitBuild/Debug/lib/libJavaScriptCore.so.1
    #10 0x0000000000000000 in ?? ()

I think the issue has to do with the (invalid) getter for v1.done, which will raise an exception (as `WeakMap` cannot be called, but must be constructed using `new`).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1910243</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-11-03 18:03:51 -0700</bug_when>
    <thetext>&lt;rdar://problem/101940070&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1912359</commentid>
    <comment_count>2</comment_count>
    <who name="Justin Michaud">justin_michaud</who>
    <bug_when>2022-11-14 10:17:21 -0800</bug_when>
    <thetext>Thank you so much for reporting this! You were absolutely right. We were missing an exception check when calling done.

Committed 256593@main (a084fca): https://commits.webkit.org/256593@main</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>