GHSA-j3px-q95c-9683: Zlib rs Zlib-rs Stack Overflow During Decompression Vulnerability

MODERATE
CVSS 5.3
CWE-770
Published
Advisory Summary

GHSA-j3px-q95c-9683 is a MODERATE (CVSS 5.3) zlib-rs stack overflow during decompression vulnerability (CWE-770: Allocation of Resources Without Limits or Throttling) affecting Zlib rs libraries in the crates.io ecosystem. The issue involves zlib-rs stack overflow during decompression with malicious input. Remediation is available by upgrading affected packages to version 0.4.0.

GHSA-j3px-q95c-9683 at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-j3px-q95c-9683
Severity MODERATE
CVSS v3.1 Base Score 5.3
CWE Classification CWE-770: Allocation of Resources Without Limits or Throttling
Affected Product Zlib rs
Package Ecosystem crates.io
Published Date
Last Updated

Security Impact

CVSS: 5.3

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity None (I:N)
Availability Low (A:L)

How to Fix GHSA-j3px-q95c-9683

To remediate this vulnerability, upgrade all affected Zlib rs dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

zlib-rs fixed: 0.4.0
Upgrade zlib-rs to 0.4.0
libz-rs-sys fixed: 0.4.0
Upgrade libz-rs-sys to 0.4.0
libz-rs-sys-cdylib fixed: 0.4.0
Upgrade libz-rs-sys-cdylib to 0.4.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for zlib-rs

How to Check if You Are Affected

To determine whether your application is affected by GHSA-j3px-q95c-9683, inspect your project dependencies for Zlib rs:

inspect dependencies for zlib-rs

Analyze the terminal output to locate any version of Zlib rs in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.4.0), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-770: Allocation of Resources Without Limits or Throttling, where the product allocates a reusable resource or group of resources on behalf of an actor without imposing any intended restrictions on the size or number of resources that can be allocated. In Zlib rs, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

A denial of service vulnerability was found in zlib-rs, triggered by specially constructed input. This input causes a stack overflow, resulting in the process using zlib-rs to crash. ### Impact Due to the way LLVM handles the zlib-rs codebase, tail calls were not guaranteed. This caused certain input patterns to result in a large number of stack frames being required, quickly resulting in a stack overflow. These are unlikely to occur in practice, but a dedicated attacker can construct malicious input files. After stack overflows were found by @inahga with a fuzzer, we dove into the assembly, and found some cases where the stack grew ```asm .LBB109_326: mov rdi, rbx call zlib_rs::inflate::State::type_do jmp .LBB109_311 .LBB109_311: lea rsp, [rbp - 40] pop rbx pop r12 pop r13 pop r14 pop r15 pop rbp .cfi_def_cfa rsp, 8 ret ``` LLVM wants to centralize the cleanup before the return (many other blocks jump to `LBB109_311`), thereby invalidating a tail call to `type_do`. We were not able to get rid of this call without introducing one elsewhere: we just don't currently have the power to tell LLVM what we want it to do. So, we switch back to loop+match waiting for changes to rust to make a more efficient implementation possible. Performance-wise, the damage is relatively minimal: we're just slower in cases where we already were slower than C. We are faster in cases where the relevant code is barely touched (in these cases the logic quickly moves into a hot inner loop and just spends most of its time there). ### Patches Version 0.4.0 patches the problem and is no longer vulnerable. ### Workarounds Users of zlib-rs should upgrade to the latest version. Users could alternatively run zlib-rs in a separate process to prevent a stack overflow crashing the entire program. In some situations a signal handler can be used to catch a stack overflow happening.

GHSA-j3px-q95c-9683 Affected Zlib rs Versions

3 component(s)
Fixed Versions:
0.4.0
Product / Package Ecosystem Affected Versions Fixed Version
zlib-rs
crates.io
< 0.4.0
0.4.0
libz-rs-sys
crates.io
< 0.4.0
0.4.0
libz-rs-sys-cdylib
crates.io
< 0.4.0
0.4.0

References

Frequently Asked Questions

What is GHSA-j3px-q95c-9683?
GHSA-j3px-q95c-9683 is a security vulnerability in Zlib rs involving zlib-rs stack overflow during decompression with malicious input under CWE-770: Allocation of Resources Without Limits or Throttling.
Which Zlib rs versions are affected?
Affected versions include releases prior to 0.4.0 across affected packages: zlib-rs, libz-rs-sys, libz-rs-sys-cdylib.
What version fixes GHSA-j3px-q95c-9683?
Upgrading to 0.4.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is zlib-rs affected?
Yes, zlib-rs is affected in releases prior to 0.4.0. Upgrade your dependency to 0.4.0 or later.
Is libz-rs-sys affected?
Yes, libz-rs-sys is affected in releases prior to 0.4.0. Upgrade your dependency to 0.4.0 or later.
What is the CVSS score of GHSA-j3px-q95c-9683?
GHSA-j3px-q95c-9683 has a CVSS v3.1 base score of 5.3 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L.
What CWE is associated with GHSA-j3px-q95c-9683?
GHSA-j3px-q95c-9683 is classified under CWE-770: Allocation of Resources Without Limits or Throttling (The product allocates a reusable resource or group of resources on behalf of an actor without imposing any intended restrictions on the size or number of resources that can be allocated.).
How can I check crates.io dependencies for GHSA-j3px-q95c-9683?
Run the dependency tree command: 'inspect dependencies for zlib-rs'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-j3px-q95c-9683",
  "modified" : "2024-12-04T16:22:50Z",
  "published" : "2024-11-14T18:09:33Z",
  "aliases" : [ ],
  "summary" : "zlib-rs stack overflow during decompression with malicious input",
  "details" : "A denial of service vulnerability was found in zlib-rs, triggered by specially constructed input. This input causes a stack overflow, resulting in the process using zlib-rs to crash.\n\n### Impact\n\nDue to the way LLVM handles the zlib-rs codebase, tail calls were not guaranteed. This caused certain input patterns to result in a large number of stack frames being required, quickly resulting in a stack overflow. These are unlikely to occur in practice, but a dedicated attacker can construct malicious input files.\n\nAfter stack overflows were found by @inahga with a fuzzer, we dove into the assembly, and found some cases where the stack grew\n\n```asm\n.LBB109_326:\n    mov rdi, rbx\n    call zlib_rs::inflate::State::type_do\n    jmp .LBB109_311\n\n.LBB109_311:\n    lea rsp, [rbp - 40]\n    pop rbx\n    pop r12\n    pop r13\n    pop r14\n    pop r15\n    pop rbp\n    .cfi_def_cfa rsp, 8\n    ret\n```\n\nLLVM wants to centralize the cleanup before the return (many other blocks jump to `LBB109_311`), thereby invalidating a tail call to `type_do`. We were not able to get rid of this call without introducing one elsewhere: we just don't currently have the power to tell LLVM what we want it to do.\n\nSo, we switch back to loop+match waiting for changes to rust to make a more efficient implementation possible. Performance-wise, the damage is relatively minimal: we're just slower in cases where we already were slower than C. We are faster in cases where the relevant code is barely touched (in these cases the logic quickly moves into a hot inner loop and just spends most of its time there).\n\n### Patches\nVersion 0.4.0 patches the problem and is no longer vulnerable.\n\n### Workarounds\nUsers of zlib-rs should upgrade to the latest version. Users could alternatively run zlib-rs in a separate process to prevent a stack overflow crashing the entire program. In some situations a signal handler can be used to catch a stack overflow happening.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "crates.io",
      "name" : "zlib-rs"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.4.0"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 0.3.1"
    }
  }, {
    "package" : {
      "ecosystem" : "crates.io",
      "name" : "libz-rs-sys"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.4.0"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 0.3.1"
    }
  }, {
    "package" : {
      "ecosystem" : "crates.io",
      "name" : "libz-rs-sys-cdylib"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.4.0"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 0.3.1"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/trifectatechfoundation/zlib-rs/security/advisories/GHSA-j3px-q95c-9683"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/trifectatechfoundation/zlib-rs"
  }, {
    "type" : "WEB",
    "url" : "https://rustsec.org/advisories/RUSTSEC-2024-0401.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-770" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-11-14T18:09:33Z",
    "nvd_published_at" : null
  }
}