# CVE-2026-27820: zlib: Buffer Overflow in Zlib::GzipReader ungetc via large input leads to memory corruption

> A buffer overflow in the Ruby zlib library allows attackers to cause memory corruption and potentially execute code via crafted gzip input.

- **Severity:** Low 1.7 (`CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N/E:U`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 16 Apr 2026
- **Updated:** 16 Apr 2026
- **Also known as:** ALPINE-CVE-2026-27820, AZL-83450, BELL-CVE-2026-27820, CLSA-2026-1785320518, CLSA-2026-1785428387, CLSA-2026-1786470325, DEBIAN-CVE-2026-27820, ECHO-cdf4-0e18-2536, GHSA-g857-hhfv-j68w, MINI-32p3-2876-68mf, MINI-74xg-wvvm-42c4, MINI-7qgg-79gq-6x4r, MINI-f9f6-rfc4-f8vg, MINI-fg53-wx78-hrqc, MINI-fpw6-8v58-wwx9, UBUNTU-CVE-2026-27820

## What is CVE-2026-27820?

CVE-2026-27820 is a low-severity memory corruption vulnerability in ruby zlib, published on 16 Apr 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

zlib is a Ruby interface for the zlib compression/decompression library. Versions 3.0.0 and below, 3.1.0, 3.1.1, 3.2.0 and 3.2.1 contain a buffer overflow vulnerability in the Zlib::GzipReader. The zstream_buffer_ungets function prepends caller-provided bytes ahead of previously produced output but fails to guarantee the backing Ruby string has enough capacity before the memmove shifts the existing data. This can lead to memory corruption when the buffer length exceeds capacity. This issue has been fixed in versions 3.0.1, 3.1.2 and 3.2.3.

Weakness: CWE-131 (Incorrect Calculation of Buffer Size), CWE-120 (Buffer Copy without Checking Size of Input)

## Which versions are affected by CVE-2026-27820?

6 open source packages ship an affected version, including zlib. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `zlib` | RubyGems | All versions | 3.0.1 |
| `zlib` | RubyGems | All versions | 3.0.1 |
| `zlib` | RubyGems | From 3.1.0 | 3.1.2 |
| `zlib` | RubyGems | From 3.1.0 | 3.1.2 |
| `zlib` | RubyGems | From 3.2.0 | 3.2.3 |
| `zlib` | RubyGems | From 3.2.0 | 3.2.3 |

Products: Ruby-Lang Zlib.

## How do I fix CVE-2026-27820?

Upgrade zlib to a fixed version for your release line: 3.0.1, 3.1.2 or 3.2.3.

## Is CVE-2026-27820 being exploited?

There is no known exploitation of CVE-2026-27820 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2026-27820 and fix it if it is affected.

What it is: CVE-2026-27820 is a low-severity memory corruption vulnerability in ruby zlib, published on 16 Apr 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2026-27820 in the wild and no public exploit code.

Affected packages and fixed versions:
- zlib (RubyGems): affected all versions; fixed in 3.0.1
- zlib (RubyGems): affected all versions; fixed in 3.0.1
- zlib (RubyGems): affected from 3.1.0; fixed in 3.1.2
- zlib (RubyGems): affected from 3.1.0; fixed in 3.1.2
- zlib (RubyGems): affected from 3.2.0; fixed in 3.2.3
- zlib (RubyGems): affected from 3.2.0; fixed in 3.2.3

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2026-27820/ (Markdown: https://insights.sbomify.com/CVE-2026-27820/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2026-27820
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2026-27820
- OSV: https://osv.dev/vulnerability/CVE-2026-27820

---
From sbomify Insights: https://insights.sbomify.com/CVE-2026-27820/
Summaries are generated and may contain mistakes; the official description above is the record.
