<?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>285746</bug_id>
          
          <creation_ts>2025-01-10 07:28:53 -0800</creation_ts>
          <short_desc>Missing Validation for Element Segment Initialization</short_desc>
          <delta_ts>2025-02-10 13:52:26 -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>
          <dependson>287432</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter>tombox1337</reporter>
          <assigned_to name="Yusuke Suzuki">ysuzuki</assigned_to>
          <cc>commit-queue</cc>
    
    <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>2086347</commentid>
    <comment_count>0</comment_count>
      <attachid>473855</attachid>
    <who name="">tombox1337</who>
    <bug_when>2025-01-10 07:28:53 -0800</bug_when>
    <thetext>Created attachment 473855
program.js

### Description
WebKit does not enforce the restriction that element segment initializers can only reference imported globals. According to the [WebAssembly specification](https://webassembly.github.io/spec/core/valid/instructions.html#constant-expressions), globals are not recursive and cannot be accessed within constant expressions when they are defined locally, affecting the initialization of element segments.

### Environment

- OS: Ubuntu 20.04
- CPU: amd64
- WebKit Version: 146fa28a329d220785d2972c1d691555141e6406

### Steps to Reproduce
Run the following WebAssembly module:
```
./JSCOnly/Debug/bin/jsc ./program.js
```

### Current State
```plaintext

(no error or warning)

```

### Expected Behavior
Per the [WebAssembly specification](https://webassembly.github.io/spec/core/valid/instructions.html#constant-expressions), element segment initializers should only be able to reference imported globals. If a locally defined global is accessed, the module should fail validation with an error similar to:
```
initializer expression can only reference an imported global
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2088035</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-01-17 07:29:12 -0800</bug_when>
    <thetext>&lt;rdar://problem/143128477&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2089472</commentid>
    <comment_count>2</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2025-01-24 00:41:46 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/39491</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2089619</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2025-01-24 13:18:05 -0800</bug_when>
    <thetext>Committed 289363@main (ed30693f477a): &lt;https://commits.webkit.org/289363@main&gt;

Reviewed commits have been landed. Closing PR #39491 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2093599</commentid>
    <comment_count>4</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2025-02-10 13:28:41 -0800</bug_when>
    <thetext>Re-opened since this is blocked by bug 287432</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2093612</commentid>
    <comment_count>5</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2025-02-10 13:52:26 -0800</bug_when>
    <thetext>This is changed in wasm GC.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>473855</attachid>
            <date>2025-01-10 07:28:53 -0800</date>
            <delta_ts>2025-01-10 07:28:53 -0800</delta_ts>
            <desc>program.js</desc>
            <filename>program.js</filename>
            <type>application/x-javascript</type>
            <size>416</size>
            <attacher>tombox1337</attacher>
            
              <data encoding="base64">CnZhciB3YXNtX2NvZGUgPSBuZXcgVWludDhBcnJheShbMCw5NywxMTUsMTA5LDEsMCwwLDAsMSw1
LDEsOTYsMCwxLDEyNywzLDIsMSwwLDQsNCwxLDExMiwwLDEsNiw2LDEsMTI3LDAsNjUsMCwxMSw3
LDgsMSw0LDEwOSw5NywxMDUsMTEwLDAsMCw5LDcsMSwwLDM1LDAsMTEsMSwwLDEwLDYsMSw0LDAs
NjUsMSwxMSwwLDE0LDQsMTEwLDk3LDEwOSwxMDEsMSw3LDEsMCw0LDEwOSw5NywxMDUsMTEwLF0p
Owp2YXIgd2FzbV9tb2R1bGUgPSBuZXcgV2ViQXNzZW1ibHkuTW9kdWxlKHdhc21fY29kZSk7CnZh
ciB3YXNtX2luc3RhbmNlID0gbmV3IFdlYkFzc2VtYmx5Lkluc3RhbmNlKHdhc21fbW9kdWxlKTsK
Y29uc3QgeyAnbWFpbic6IGZ1bmMgfSA9IHdhc21faW5zdGFuY2UuZXhwb3J0czsKdmFyIGEgPSBm
dW5jKCk7CnByaW50KGEpOwo=
</data>

          </attachment>
      

    </bug>

</bugzilla>