# GHSA-9q78-27f3-2jmh: webp crate may expose memory contents when encoding an image

> An attacker can trigger out-of-bounds reads in the webp crate by providing a short input buffer, leading to memory exposure or crashes.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 6 Sep 2024
- **Also known as:** RUSTSEC-2024-0443

## What is GHSA-9q78-27f3-2jmh?

GHSA-9q78-27f3-2jmh is a memory corruption vulnerability in webp, published on 6 Sep 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Affected versions of this crate did not check that the input slice passed to `"webp::Encoder::encode()` is large enough for the specified image dimensions.

If the input slice is too short, the library will read out of bounds of the buffer and encode other memory contents as an image, resulting in memory exposure or a segmentation fault.

The flaw was corrected in [pull request #44](https://github.com/jaredforth/webp/pull/44) by always validating the input buffer size when constructing the encoder.

## Which versions are affected by GHSA-9q78-27f3-2jmh?

3 open source packages ship an affected version, including webp.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `webp` | crates.io | All versions | 0.3.1 |
| `webp` | crates.io | All versions | 0.3.1 |
| `webp` | crates.io | From 0.0.0-0 | 0.3.1 |

## How do I fix GHSA-9q78-27f3-2jmh?

Upgrade webp to 0.3.1 or later.

## Is GHSA-9q78-27f3-2jmh being exploited?

There is no known exploitation of GHSA-9q78-27f3-2jmh in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-9q78-27f3-2jmh and fix it if it is affected.

What it is: GHSA-9q78-27f3-2jmh is a memory corruption vulnerability in webp, published on 6 Sep 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-9q78-27f3-2jmh in the wild and no public exploit code.

Affected packages and fixed versions:
- webp (crates.io): affected all versions; fixed in 0.3.1
- webp (crates.io): affected all versions; fixed in 0.3.1
- webp (crates.io): affected from 0.0.0-0; fixed in 0.3.1

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/GHSA-9q78-27f3-2jmh/ (Markdown: https://insights.sbomify.com/GHSA-9q78-27f3-2jmh/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-9q78-27f3-2jmh

---
From sbomify Insights: https://insights.sbomify.com/GHSA-9q78-27f3-2jmh/
Summaries are generated and may contain mistakes; the official description above is the record.
