<?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>256330</bug_id>
          
          <creation_ts>2023-05-04 12:41:28 -0700</creation_ts>
          <short_desc>Unexpected &quot;Extra bytes past the end&quot; error when decompressing data with DecompressionStream</short_desc>
          <delta_ts>2023-05-17 13:35: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>WebKit Misc.</component>
          <version>Safari 16</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>macOS 13</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>254021</dup_id>
          
          <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 name="gildas">gildas.lormeau</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>32jojo32</cc>
    
    <cc>achristensen</cc>
    
    <cc>ap</cc>
    
    <cc>ashley</cc>
    
    <cc>bfulgham</cc>
    
    <cc>brandonstewart</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>youennf</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1952979</commentid>
    <comment_count>0</comment_count>
    <who name="gildas">gildas.lormeau</who>
    <bug_when>2023-05-04 12:41:28 -0700</bug_when>
    <thetext>I&apos;m the author of zip.js, see https://github.com/gildas-lormeau/zip.js/. A user has reported a bug that is specific to Safari. This bug is a regression introduced in the version 16.4. An unexpected error &quot;TypeError: Extra bytes past the end&quot; is thrown when unzipping a file. When disabling the usage of the `DecompressionStream` API in zip.js (via the option `useCompressionStream`), the bug disappears.

Unfortunately, I cannot provide this zip file. You can find more information here: https://github.com/gildas-lormeau/zip.js/issues/412</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1953046</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2023-05-04 16:55:50 -0700</bug_when>
    <thetext>Thank you for the report! Unfortunately, this seems unlikely to be actionable without an example archive.

&gt; This bug is a regression introduced in the version 16.4.

Could you please elaborate on this? Safari 16.4 is the first version to support DecompressionStream, so it could never work differently before. Are you saying that something used to work as expected using a polyfill, and doesn&apos;t work with native implementation?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1953055</commentid>
    <comment_count>2</comment_count>
    <who name="gildas">gildas.lormeau</who>
    <bug_when>2023-05-04 17:45:27 -0700</bug_when>
    <thetext>Indeed, I was meaning it&apos;s a regression in zip.js that has been introduced by Safari 16.4. In Safari 16.3 (and Firefox), zip.js uses its own implementation. Note that zip.js does not contain user-agent sniffing code. Therefore, I am very reluctant to circumvent it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1953056</commentid>
    <comment_count>3</comment_count>
    <who name="gildas">gildas.lormeau</who>
    <bug_when>2023-05-04 17:48:18 -0700</bug_when>
    <thetext>By the way, what is the &quot;TypeError: Extra bytes past the end&quot; error? It does not seem to be specified here: https://wicg.github.io/compression/#compression-stream.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1953061</commentid>
    <comment_count>4</comment_count>
    <who name="gildas">gildas.lormeau</who>
    <bug_when>2023-05-04 18:15:39 -0700</bug_when>
    <thetext>Actually, the error seems to be thrown when reading 128 bytes at the offset 1664 of a compressed stream weighting 247,454 bytes. It looks like the error would be thrown probably when creating a `Uint8Array()` of 128 bytes containing the decompressed data.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1953063</commentid>
    <comment_count>5</comment_count>
    <who name="gildas">gildas.lormeau</who>
    <bug_when>2023-05-04 18:18:07 -0700</bug_when>
    <thetext>Sorry, I was meaning &quot;128 bytes containing the **compressed** data.&quot; in the last sentence of my last comment.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1953188</commentid>
    <comment_count>6</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2023-05-05 08:55:40 -0700</bug_when>
    <thetext>It&apos;s raised here: https://github.com/WebKit/WebKit/blob/main/Source/WebCore/Modules/compression/DecompressionStreamDecoder.cpp#L138.

I am not familiar with this API or code, but from quickly glancing at the spec, it does specify raising a TypeError for decoding errors.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1953189</commentid>
    <comment_count>7</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-05-05 08:55:55 -0700</bug_when>
    <thetext>&lt;rdar://problem/108950984&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1953213</commentid>
    <comment_count>8</comment_count>
    <who name="gildas">gildas.lormeau</who>
    <bug_when>2023-05-05 11:01:56 -0700</bug_when>
    <thetext>Thank you for the additional info. It looks like this issue is very similar to these ones in zip.js: https://github.com/gildas-lormeau/zip.js/issues/44, https://github.com/gildas-lormeau/zip.js/issues/101.

I&apos;m trying to find the zip file that was attached. It also looks like it was possible to reproduce the issue by using .NET&apos;s DeflateStream in 2013 (see first link).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1953271</commentid>
    <comment_count>9</comment_count>
    <who name="gildas">gildas.lormeau</who>
    <bug_when>2023-05-05 13:11:43 -0700</bug_when>
    <thetext>I was not able to find the zip file unfortunately.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1953281</commentid>
    <comment_count>10</comment_count>
    <who name="gildas">gildas.lormeau</who>
    <bug_when>2023-05-05 13:50:36 -0700</bug_when>
    <thetext>I was able to find an example of code to reproduce the issue inspired from this thread on SO: https://stackoverflow.com/questions/67526864/how-to-inflate-a-gzip-with-a-really-old-zlib.

Steps to reproduce the issue:
- Open a new tab in Safari
- Open the developer tools
- Run the code below
`
(async () =&gt; {
	const result = new TransformStream();
	(new Blob([new Uint8Array([0xec, 0x9a, 0x7f, 0x54, 0x1c, 0x55, 0x96, 0xc7, 0x6f, 0x75, 0x37, 0xd0, 0xfc, 0x70])])).stream().pipeThrough(new DecompressionStream(&quot;deflate-raw&quot;)).pipeTo(result.writable);
	console.log(await new Response(result.readable).blob());
})();
`

Expected result:
An error similar to &quot;TypeError: The input is ended without reaching the stream end&quot; (Firefox) or &quot;TypeError: Compressed input was truncated.&quot; (Chrome) should be thrown.

Result in Safari 16.4:
The error &quot;TypeError: Extra bytes past the end.&quot; is thrown instead.

The code run as expected in:
- Firefox nightly: yes
- Chrome: yes</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1953338</commentid>
    <comment_count>11</comment_count>
    <who name="gildas">gildas.lormeau</who>
    <bug_when>2023-05-05 17:46:50 -0700</bug_when>
    <thetext>Sorry, forget my last comment. I think my test is wrong.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1955622</commentid>
    <comment_count>12</comment_count>
    <who name="Jozef">32jojo32</who>
    <bug_when>2023-05-16 03:28:53 -0700</bug_when>
    <thetext>I believe I might have a better example. The example I share tries to compress text and then decompress. Chrome handles it correctly. Unfortunately text is pretty long as I was not able to replicate it on smaller substring.


To replicate the bug open the file and you should see one error log and one success log. Chrome shows two success logs.

https://gist.github.com/Joozty/3bd03a81d4d6540eaea683d9c6389703</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1955684</commentid>
    <comment_count>13</comment_count>
    <who name="Brandon">brandonstewart</who>
    <bug_when>2023-05-16 09:35:48 -0700</bug_when>
    <thetext>@Jozef Thanks for the test case; I just tried your example and in Safari and STP I was seeing the issue. 

When I tried a build off of mainline though I am seeing 2 success messages in the console (using MiniBrower).


I integrated a fix a few days ago that handled an edge case during the flush step.

https://github.com/WebKit/WebKit/pull/13741</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1955881</commentid>
    <comment_count>14</comment_count>
    <who name="Ashley Gullen">ashley</who>
    <bug_when>2023-05-17 05:04:43 -0700</bug_when>
    <thetext>So did Safari 16.4 ship broken CompressionStreams when using large amounts of content? This in turn would break the zip.js library in many cases, and would explain why we&apos;ve been getting a bunch of customer support queries about errors opening zip-based content in our web app...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1955993</commentid>
    <comment_count>15</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2023-05-17 13:02:06 -0700</bug_when>
    <thetext>(In reply to Ashley Gullen from comment #14)
&gt; So did Safari 16.4 ship broken CompressionStreams when using large amounts
&gt; of content? This in turn would break the zip.js library in many cases, and
&gt; would explain why we&apos;ve been getting a bunch of customer support queries
&gt; about errors opening zip-based content in our web app...

Compression Streams first shipped in Safari 16.4, so yes -- these bugs would be new with that release.

We think this issue is a duplicate of Bug 254021, which has a test case that we were able to use to confirm and fix.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1956005</commentid>
    <comment_count>16</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2023-05-17 13:35:17 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 254021 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>