<?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>309760</bug_id>
          
          <creation_ts>2026-03-11 23:45:31 -0700</creation_ts>
          <short_desc>ZStream::~ZStream() should call inflateEnd() for decompression mode</short_desc>
          <delta_ts>2026-03-19 18:41:54 -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>WebCore Misc.</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=280445</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Fujii Hironori">fujii</reporter>
          <assigned_to name="Fujii Hironori">fujii</assigned_to>
          <cc>brandonstewart</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2189428</commentid>
    <comment_count>0</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2026-03-11 23:45:31 -0700</bug_when>
    <thetext>Claude Code reported:

**Severity:** Low — technically undefined behavior but zlib handles it gracefully
**Type:** Logic bug (not a crash)
**Reproducible:** Always present in code, but does not trigger ASAN

### Location

**File:** `Source/WebCore/Modules/compression/ZStream.cpp`, line 83

```cpp
ZStream::~ZStream()
{
    if (m_isInitialized)
        deflateEnd(&amp;m_stream);  // BUG: always calls deflateEnd, even for inflate streams
}
```

### Root cause

The `ZStream` class tracks `m_isInitialized` (bool) but does not track the `Operation` type (Compression vs Decompression). The destructor unconditionally calls `deflateEnd()`. For decompression streams initialized via `inflateInit2()`, the correct call is `inflateEnd()`.

Per the zlib API, calling `deflateEnd()` on an inflate stream is undefined behavior. In practice, zlib&apos;s internal state checking returns `Z_STREAM_ERROR` without corrupting memory.

### Suggested fix

Add an `Operation` member to `ZStream` and call the correct cleanup:

```cpp
// In ZStream.h:
Operation m_operation;

// In ZStream.cpp destructor:
ZStream::~ZStream()
{
    if (m_isInitialized) {
        if (m_operation == Operation::Compression)
            deflateEnd(&amp;m_stream);
        else
            inflateEnd(&amp;m_stream);
    }
}
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2190257</commentid>
    <comment_count>1</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2026-03-13 22:21:46 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/60621</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2191168</commentid>
    <comment_count>2</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2026-03-17 16:22:17 -0700</bug_when>
    <thetext>Dupe of bug#302216. Closed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2191898</commentid>
    <comment_count>3</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2026-03-19 18:41:54 -0700</bug_when>
    <thetext>Fixed by 309446@main.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>