<?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>250558</bug_id>
          
          <creation_ts>2023-01-13 03:29:05 -0800</creation_ts>
          <short_desc>texSubImage2D crashed on iOS16 + WebGL2 + large WASM memory</short_desc>
          <delta_ts>2023-05-22 01:23:18 -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>WebGL</component>
          <version>WebKit Local Build</version>
          <rep_platform>iPhone / iPad</rep_platform>
          <op_sys>iOS 16</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>fuyoucheng</reporter>
          <assigned_to name="Kimmo Kinnunen">kkinnunen</assigned_to>
          <cc>dino</cc>
    
    <cc>kbr</cc>
    
    <cc>kkinnunen</cc>
    
    <cc>ruba.merza</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1925287</commentid>
    <comment_count>0</comment_count>
    <who name="">fuyoucheng</who>
    <bug_when>2023-01-13 03:29:05 -0800</bug_when>
    <thetext>How to reproduce:
1. Create a new Untiy WebGL project with an empty scene, 
2. Set graphic api to WebGL2，
3. Set WASM initial memory to a large size (by adding &quot;-s TOTAL_MEMORY=768MB&quot; to PlayerSettings.WebGL.emscriptenArgs)
4. Build and load with Safari on iPhone12 with iOS16,
5. Safari report error when loading.

Rootcause:
Unity called texSubImage2D during initialization, Safari report error when invoking this api due to insufficient memory.
But that texture is 4*4 RGBA UNSIGNED_BYTE, should not cause any memory pressure.
When looking into WebGL2RenderingContext::texSubImage2D in WebKit source code, we found:
In WebGLRenderingContextBase::texImageArrayBufferViewHelper, variable &apos;data&apos; created by WebGLRenderingContextBase::validateTexFuncData has incorrect value.
data.m_bufSize ought to be pixel data length, but acturally assigned as arrayBuffer(whole WASM memory) length - pixel data offset, which is much more larger.
Then later in IPC::Encoder::encodeFixedLengthData, encoder buffer will grow by this large size and lead to memory issue.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1925854</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-01-16 12:38:23 -0800</bug_when>
    <thetext>&lt;rdar://problem/104305743&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1930014</commentid>
    <comment_count>2</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2023-02-01 00:38:28 -0800</bug_when>
    <thetext>*** Bug 250862 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1930015</commentid>
    <comment_count>3</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2023-02-01 00:38:48 -0800</bug_when>
    <thetext>See bug 250558 for a test case</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1930094</commentid>
    <comment_count>4</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2023-02-01 06:51:29 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/9451</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1930390</commentid>
    <comment_count>5</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-02-02 00:40:03 -0800</bug_when>
    <thetext>Committed 259742@main (905fdd75fe5d): &lt;https://commits.webkit.org/259742@main&gt;

Reviewed commits have been landed. Closing PR #9451 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1956868</commentid>
    <comment_count>6</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2023-05-22 01:23:18 -0700</bug_when>
    <thetext>The fix shipped in iOS 16.4, macOS 12.3, Safari 16.4</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>