# GHSA-v8gq-5grq-9728: mozjpeg DecompressScanlines::read_scanlines is Unsound

> Unsound memory handling in mozjpeg allows attackers to cause memory corruption or arbitrary code execution via crafted images.

- **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:** 4 Jul 2020
- **Also known as:** RUSTSEC-2020-0165

## What is GHSA-v8gq-5grq-9728?

GHSA-v8gq-5grq-9728 is a memory corruption vulnerability in mozjpeg, published on 4 Jul 2020. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

This issue and vector is similar to [RUSTSEC-2020-0029] of `rgb` crate which `mozjpeg` depends on.

Affected versions of `mozjpeg` crate allow creating instances of any type `T` from bytes,
and do not correctly constrain `T` to the types for which it is safe to do so.

Examples of safety violation possible for a type `T`:

* `T` contains a reference type, and it constructs a pointer to an invalid, arbitrary memory address.
* `T` requires a safety and/or validity invariant for its construction that may be violated.

The issue was fixed in 0.8.19 by using safer types and involving `rgb` dependency bump.

[RUSTSEC-2020-0029]: https://rustsec.org/advisories/RUSTSEC-2020-0029.html

## Which versions are affected by GHSA-v8gq-5grq-9728?

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


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

## How do I fix GHSA-v8gq-5grq-9728?

Upgrade mozjpeg to 0.8.19 or later.

## Is GHSA-v8gq-5grq-9728 being exploited?

There is no known exploitation of GHSA-v8gq-5grq-9728 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-v8gq-5grq-9728 and fix it if it is affected.

What it is: GHSA-v8gq-5grq-9728 is a memory corruption vulnerability in mozjpeg, published on 4 Jul 2020. 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-v8gq-5grq-9728 in the wild and no public exploit code.

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

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-v8gq-5grq-9728/ (Markdown: https://insights.sbomify.com/GHSA-v8gq-5grq-9728/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-v8gq-5grq-9728

---
From sbomify Insights: https://insights.sbomify.com/GHSA-v8gq-5grq-9728/
Summaries are generated and may contain mistakes; the official description above is the record.
