# GHSA-jwh2-vrr9-vcp2: mz-avro's incorrect use of `set_len` allows for un-initialized memory

> Attackers can exploit unidiomatic Read implementations to expose uninitialized memory or cause undefined behavior in applications using the mz-avro crate.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Not stated
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 14 Oct 2021
- **Also known as:** RUSTSEC-2021-0138

## What is GHSA-jwh2-vrr9-vcp2?

GHSA-jwh2-vrr9-vcp2 is a memory corruption vulnerability in mz-avro, published on 14 Oct 2021. 

### Official description

Affected versions of this crate passes an uninitialized buffer to a user-provided `Read` 
implementation.

Arbitrary `Read` implementations can read from the uninitialized buffer (memory exposure)
and also can return incorrect number of bytes written to the buffer.
Reading from uninitialized memory produces undefined values that can quickly invoke
undefined behavior.

Note: there is only UB in the case where a user provides a struct whose `Read`
implementation inspects the buffer passed to `read_exact` before writing to it.
This is an unidiomatic (albeit possible) `Read` implementation.

See https://github.com/MaterializeInc/materialize/issues/8669 for details.

## Which versions are affected by GHSA-jwh2-vrr9-vcp2?

3 open source packages ship an affected version, including mz-avro.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `mz-avro` | crates.io | All versions | 0.7.0 |
| `mz-avro` | crates.io | All versions | 0.7.0 |
| `mz-avro` | crates.io | From 0.0.0-0 | 0.7.0 |

## How do I fix GHSA-jwh2-vrr9-vcp2?

Upgrade mz-avro to 0.7.0 or later.

## Is GHSA-jwh2-vrr9-vcp2 being exploited?

There is no known exploitation of GHSA-jwh2-vrr9-vcp2 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-jwh2-vrr9-vcp2 and fix it if it is affected.

What it is: GHSA-jwh2-vrr9-vcp2 is a memory corruption vulnerability in mz-avro, published on 14 Oct 2021. 
Exploitation: There is no known exploitation of GHSA-jwh2-vrr9-vcp2 in the wild and no public exploit code.

Affected packages and fixed versions:
- mz-avro (crates.io): affected all versions; fixed in 0.7.0
- mz-avro (crates.io): affected all versions; fixed in 0.7.0
- mz-avro (crates.io): affected from 0.0.0-0; fixed in 0.7.0

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-jwh2-vrr9-vcp2/ (Markdown: https://insights.sbomify.com/GHSA-jwh2-vrr9-vcp2/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-jwh2-vrr9-vcp2

---
From sbomify Insights: https://insights.sbomify.com/GHSA-jwh2-vrr9-vcp2/
Summaries are generated and may contain mistakes; the official description above is the record.
