<?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>290681</bug_id>
          
          <creation_ts>2025-03-28 23:50:31 -0700</creation_ts>
          <short_desc>&quot;call_indirect to a null table entry&quot; after 230257 wasm table grows</short_desc>
          <delta_ts>2025-10-19 12:29:17 -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>Safari Technology Preview</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>macOS 15</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>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>terrorjack</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>terrorjack</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2107079</commentid>
    <comment_count>0</comment_count>
    <who name="">terrorjack</who>
    <bug_when>2025-03-28 23:50:31 -0700</bug_when>
    <thetext>Hi folks, I&apos;m running a wasm dynamic linker written in JS (https://gitlab.haskell.org/ghc/ghc/-/blob/master/utils/jsffi/dyld.mjs) in browser, which allocates an anyfunc table with initial size 1, and invokes table.grow(1, func) 230257 times, and the table growth is interleaved with wasm execution. Now, it works fine in firefox/chrome, but in safari (both 18.3.1 and TP215) I&apos;m seeing spurious &quot;call_indirect to a null table entry&quot; panics when the wasm code attempts to call_indirect into small indices of the table. The panic can be worked around by allocating a huge table upfront and never growing it, only filling the slots in the dynamic linker logic.

I can provide more detailed instructions to reproduce if it helps, but it&apos;s not a single script and a bunch of wasm payloads, it requires installing a bunch of tools to proceed. So I&apos;m just reporting the above information for now to see if it rings any bells.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2109133</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-04-05 11:40:17 -0700</bug_when>
    <thetext>&lt;rdar://problem/148665183&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2109330</commentid>
    <comment_count>2</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2025-04-06 21:51:35 -0700</bug_when>
    <thetext>Thanks! Can you attach the test case to reproduce the issue?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2110900</commentid>
    <comment_count>3</comment_count>
    <who name="">terrorjack</who>
    <bug_when>2025-04-14 10:25:02 -0700</bug_when>
    <thetext>Hi, I&apos;ve created a relocatable binary distribution of the ghc wasm toolchain on aarch64-darwin at https://drive.google.com/file/d/13Gi_-1lMqD-HUJhb_4YVgYffPteWqPVY/view?usp=sharing. Here are the steps to use it to reproduce the issue:

- Download and extract it to a temporary path
- `export PATH=$PWD/.ghc-wasm/nodejs/bin:$PATH`
- `export NODE_PATH=$PWD/.ghc-wasm/nodejs/lib/node_modules`
- `./.ghc-wasm/wasm32-wasi-ghc/bin/wasm32-wasi-ghc --interactive -fghci-browser -fghci-browser-port=8000`

You&apos;ll see a prompt like `Open http://127.0.0.1:8000/main.html or import http://127.0.0.1:8000/main.js to boot ghci`. You can now open Safari and open the inspector panel, open the page as instructed, the `wasm32-wasi-ghc` console will be unfrozen and accept user input. Now, the crash in this bug can be reproduced by typing the following two lines:

- `foreign import javascript &quot;new Promise(res =&gt; setTimeout(res, 1024, 114514))&quot; test :: IO Int`
- `test`

You can also modify `./.ghc-wasm/wasm32-wasi-ghc/lib/dyld.mjs` script in place, that&apos;s the dynamic linker program we&apos;re using. Let me know if there&apos;s any difficulty in the reproducer, thanks a lot!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2152444</commentid>
    <comment_count>4</comment_count>
    <who name="">terrorjack</who>
    <bug_when>2025-10-19 12:29:17 -0700</bug_when>
    <thetext>So it turns out that the table.grow() JS API is broken, but the table.grow wasm instruction works, so this issue can be worked around by calling a wasm function that&apos;s in charge of growing the table. I&apos;ve implemented the workaround in https://gitlab.haskell.org/ghc/ghc/-/merge_requests/14988, but it would still be nice for upstream to fix it some day.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>