<?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>186641</bug_id>
          
          <creation_ts>2018-06-14 19:18:08 -0700</creation_ts>
          <short_desc>wasm marshalArgument unanble to correcly handle type B3:void</short_desc>
          <delta_ts>2018-08-08 20:04:25 -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>WebAssembly</component>
          <version>WebKit Local Build</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</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>dwfault</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>fpizlo</cc>
    
    <cc>keith_miller</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1433218</commentid>
    <comment_count>0</comment_count>
      <attachid>342784</attachid>
    <who name="">dwfault</who>
    <bug_when>2018-06-14 19:18:08 -0700</bug_when>
    <thetext>Created attachment 342784
The sample would make jsc crash.

marshalArugument in WebAssembly of JavaScriptCore could not correcly handle type B3::void as argument function signature. Tested on git commit 


The byte 0x70 in section Type was added up to 0xf0, in:

    template&lt;typename SuccessType&gt;
    ALWAYS_INLINE bool Parser&lt;SuccessType&gt;::parseInt7(int8_t&amp; result)
    {
        if (m_offset &gt;= length())
            return false;
        uint8_t v = source()[m_offset++];
        result = (v &amp; 0x40) ? WTF::bitwise_cast&lt;int8_t&gt;(uint8_t(v | 0x80)) : v;
        return (v &amp; 0x80) == 0;
    }


    template&lt;typename Functor&gt;
    void loadArguments(const Signature&amp; signature, B3::Procedure&amp; proc, B3::BasicBlock* block, B3::Origin origin, const Functor&amp; functor) const
    {
        B3::Value* framePointer = block-&gt;appendNew&lt;B3::Value&gt;(proc, B3::FramePointer, origin);

        size_t gpArgumentCount = 0;
        size_t fpArgumentCount = 0;
        size_t stackOffset = headerSize;

        for (size_t i = 0; i &lt; signature.argumentCount(); ++i) {
            B3::Type type = toB3Type(signature.argument(i));                                           ---&gt; In the function &quot;toB3Type&quot; byte 0xf0 is passed in, and B3::Void is returned.
            B3::Value* argument;
            B3::ValueRep rep = marshallArgument(type, gpArgumentCount, fpArgumentCount, stackOffset);    ---&gt; In this function &quot;marshallArgument&quot;, B3::Void cannot be handled correcly, which caused a crash.
            if (rep.isReg()) {
                argument = block-&gt;appendNew&lt;B3::ArgumentRegValue&gt;(proc, origin, rep.reg());
                if (type == B3::Int32 || type == B3::Float)
                    argument = block-&gt;appendNew&lt;B3::Value&gt;(proc, B3::Trunc, origin, argument);
            } else {
                ASSERT(rep.isStackArgument());
                B3::Value* address = block-&gt;appendNew&lt;B3::Value&gt;(proc, B3::Add, origin, framePointer,
                    block-&gt;appendNew&lt;B3::Const64Value&gt;(proc, origin, rep.offsetFromSP()));
                argument = block-&gt;appendNew&lt;B3::MemoryValue&gt;(proc, B3::Load, type, origin, address);
            }
            functor(argument, i);
        }
    }



The crash happened here:

    B3::ValueRep marshallArgument(B3::Type type, size_t&amp; gpArgumentCount, size_t&amp; fpArgumentCount, size_t&amp; stackOffset) const
    {
        switch (type) {
        case B3::Int32:
        case B3::Int64:
            return marshallArgumentImpl(m_gprArgs, type, gpArgumentCount, stackOffset);
        case B3::Float:
        case B3::Double:
            return marshallArgumentImpl(m_fprArgs, type, fpArgumentCount, stackOffset);
        case B3::Void:
            break;
        }
        RELEASE_ASSERT_NOT_REACHED();     ---&gt;crash.
    }</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1433219</commentid>
    <comment_count>1</comment_count>
    <who name="">dwfault</who>
    <bug_when>2018-06-14 19:19:16 -0700</bug_when>
    <thetext>Tested on git commit 57ff755</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1448913</commentid>
    <comment_count>2</comment_count>
    <who name="Keith Miller">keith_miller</who>
    <bug_when>2018-08-08 20:03:31 -0700</bug_when>
    <thetext>I think this was fixed by: http://trac.webkit.org/r232970.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1448914</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2018-08-08 20:04:25 -0700</bug_when>
    <thetext>&lt;rdar://problem/43076679&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>342784</attachid>
            <date>2018-06-14 19:18:08 -0700</date>
            <delta_ts>2018-06-14 19:18:08 -0700</delta_ts>
            <desc>The sample would make jsc crash.</desc>
            <filename>PoC.js</filename>
            <type>application/x-javascript</type>
            <size>511</size>
            <attacher>dwfault</attacher>
            
              <data encoding="base64">dmFyIHdhc21Nb2R1bGUgPSBuZXcgV2ViQXNzZW1ibHkuTW9kdWxlKG5ldyBVaW50OEFycmF5KFsw
eDAsMHg2MSwweDczLDB4NmQsMHgxLDB4MCwweDAsMHgwLDB4MSwweGYsMHgxLDB4NjAsMHhhLDB4
NzAsMHg3YywweDdjLDB4N2MsMHg3YywweDdjLDB4N2MsMHg3YywweDdjLDB4N2MsMHgxLDB4N2Ms
MHgzLDB4MiwweDEsMHgwLDB4YSwweDMxLDB4MSwweDJmLDB4MCwweDIwLDB4MCwweDIwLDB4MSww
eDIwLDB4MiwweDIwLDB4MywweDIwLDB4MiwweDIwLDB4MywweDIwLDB4NCwweDIwLDB4NSwweDIw
LDB4NiwweDAsMHgwLDB4MCwweDAsMHgyMCwweDksMHgxMCwweDAsMHgwLDB4MTAsMHgwLDB4Yiww
eDAsMHhlLDB4NCwweDZlLDB4NjEsMHg2ZCwweDY0LDB4MSwweDcsMHgxLDB4MSwweDQsMHg2ZCww
eDI3LDB4NjksMHg2ZSxdKSk7CnZhciB3YXNtSW5zdGFuY2UgPSBuZXcgV2ViQXNzZW1ibHkuSW5z
dGFuY2Uod2FzbU1vZHVsZSk7CnByaW50KHdhc21JbnN0YW5jZS5leHBvcnRzLm1haW4oKSk7Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>