<?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>285505</bug_id>
          
          <creation_ts>2025-01-07 02:33:10 -0800</creation_ts>
          <short_desc>Incorrect Index Validation in grow_memory Instruction</short_desc>
          <delta_ts>2025-01-30 22:20:39 -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>Other</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</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>
          
          <blocked>277743</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter>tombox1337</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>d_degazio</cc>
    
    <cc>keith_miller</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>2085368</commentid>
    <comment_count>0</comment_count>
      <attachid>473821</attachid>
    <who name="">tombox1337</who>
    <bug_when>2025-01-07 02:33:10 -0800</bug_when>
    <thetext>Created attachment 473821
program.js

### Description
WebKit does not correctly enforce validation for the `grow_memory` instruction in WebAssembly modules.

### Environment

- OS: Ubuntu 20.04  
- CPU: amd64  
- WebKit Version: 146fa28a329d220785d2972c1d691555141e6406
- Commands:  
```bash
./JSCOnly/Debug/bin/jsc ./program.js
```

### Test Case

program.js



### Current State
```plaintext
./JSCOnly/Debug/bin/jsc ./program.js
Exception: CompileError: WebAssembly.Module doesn&apos;t parse at byte 5: reserved byte for grow_memory must be zero, in function at index 0 (evaluating &apos;new WebAssembly.Module(wasm_code)&apos;)
Module@[native code]
```

### Expected Behavior

The WebAssembly module should fail validation and report an error similar to:

- Like gecko-dev:
  ```plaintext
  memory index out of range for memory.grow
  ```
- Like v8:
  ```plaintext
  CompileError: WebAssembly.Module(): Compiling function #0 failed: memory index 2816 exceeds number of declared memories (1) 
  ```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2085511</commentid>
    <comment_count>1</comment_count>
    <who name="David Degazio">d_degazio</who>
    <bug_when>2025-01-07 11:05:55 -0800</bug_when>
    <thetext>It looks like we&apos;re still failing at validation time, just reporting a different error message? &quot;must be zero&quot; is more appropriate for WebKit at the moment than &quot;out of range&quot; because we do not yet support the WASM multi-memory proposal (tracked in https://bugs.webkit.org/show_bug.cgi?id=277743).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2085512</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-01-07 11:06:18 -0800</bug_when>
    <thetext>&lt;rdar://problem/142489712&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2090917</commentid>
    <comment_count>3</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2025-01-30 22:20:39 -0800</bug_when>
    <thetext>multi-memory is not implemented.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>473821</attachid>
            <date>2025-01-07 02:33:10 -0800</date>
            <delta_ts>2025-01-07 02:33:10 -0800</delta_ts>
            <desc>program.js</desc>
            <filename>file_285505.txt</filename>
            <type>text/plain</type>
            <size>236</size>
            <attacher>tombox1337</attacher>
            
              <data encoding="base64">DQp2YXIgd2FzbV9jb2RlID0gbmV3IFVpbnQ4QXJyYXkoWzAsOTcsMTE1LDEwOSwxLDAsMCwwLDEs
NCwxLDk2LDAsMCwzLDIsMSwwLDUsMywxLDAsMCwxMCwxMCwxLDgsMCw2NSwwLDY0LDEyOCwyMiwy
NiwxMSxdKTsNCnZhciB3YXNtX21vZHVsZSA9IG5ldyBXZWJBc3NlbWJseS5Nb2R1bGUod2FzbV9j
b2RlKTsNCnZhciB3YXNtX2luc3RhbmNlID0gbmV3IFdlYkFzc2VtYmx5Lkluc3RhbmNlKHdhc21f
bW9kdWxlKTs=
</data>

          </attachment>
      

    </bug>

</bugzilla>