<?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>234967</bug_id>
          
          <creation_ts>2022-01-07 10:38:47 -0800</creation_ts>
          <short_desc>JSC::Wasm::setWasmTableElement() falls through ASSERT_NOT_REACHED()</short_desc>
          <delta_ts>2022-01-21 09:23:32 -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>WebAssembly</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></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>
          <dependson>234932</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="David Kilzer (:ddkilzer)">ddkilzer</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>keith_miller</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1828970</commentid>
    <comment_count>0</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2022-01-07 10:38:47 -0800</bug_when>
    <thetext>JSC::Wasm::setWasmTableElement() falls through ASSERT_NOT_REACHED().

The functions should return `false` after both ASSERT_NOT_REACHED() statements rather than falling through and returning `true`.

static bool setWasmTableElement(Instance* instance, unsigned tableIndex, uint32_t index, EncodedJSValue encValue)
{   
    ASSERT(tableIndex &lt; instance-&gt;module().moduleInformation().tableCount());
    
    if (index &gt;= instance-&gt;table(tableIndex)-&gt;length())
        return false;
    
    JSValue value = JSValue::decode(encValue); 
    if (instance-&gt;table(tableIndex)-&gt;type() == Wasm::TableElementType::Externref)
        instance-&gt;table(tableIndex)-&gt;set(index, value);
    else if (instance-&gt;table(tableIndex)-&gt;type() == Wasm::TableElementType::Funcref) {
        WebAssemblyFunction* wasmFunction;
        WebAssemblyWrapperFunction* wasmWrapperFunction;
        
        if (isWebAssemblyHostFunction(instance-&gt;owner&lt;JSObject&gt;()-&gt;vm(), value, wasmFunction, wasmWrapperFunction)) {
            ASSERT(!!wasmFunction || !!wasmWrapperFunction);
            if (wasmFunction)
                instance-&gt;table(tableIndex)-&gt;asFuncrefTable()-&gt;setFunction(index, jsCast&lt;JSObject*&gt;(value), wasmFunction-&gt;importableFunction(), &amp;wasmFunction-&gt;instance()-&gt;instance());
            else
                instance-&gt;table(tableIndex)-&gt;asFuncrefTable()-&gt;setFunction(index, jsCast&lt;JSObject*&gt;(value), wasmWrapperFunction-&gt;importableFunction(), &amp;wasmWrapperFunction-&gt;instance()-&gt;instance());
        } else if (value.isNull())
            instance-&gt;table(tableIndex)-&gt;clear(index);
        else
            ASSERT_NOT_REACHED();
    } else
        ASSERT_NOT_REACHED();
    
    return true;
}

See Source/JavaScriptCore/wasm/WasmOperations.cpp.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1828971</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-01-07 10:39:05 -0800</bug_when>
    <thetext>&lt;rdar://problem/87260620&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1832792</commentid>
    <comment_count>2</comment_count>
    <who name="Keith Miller">keith_miller</who>
    <bug_when>2022-01-21 09:23:32 -0800</bug_when>
    <thetext>I don&apos;t think it matters if it returns `true` or `false`. That return boolean is to flag whether an Out of Bounds memory exception should be thrown but any access triggering one of those asserts isn&apos;t out of bounds.

Do you think that an OoB exception is better than a no-op if we have a bug in our implementation? It seems to me a no-op is easier to work around for a dev?</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>