# GHSA-3jch-9qgp-4844: Generated code can read and write out of bounds in safe code

> Attackers can trigger memory corruption and potential code execution by providing malformed input to unsafe code generated by the flatbuffers compiler.

- **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:** 31 Oct 2021
- **Also known as:** RUSTSEC-2021-0122

## What is GHSA-3jch-9qgp-4844?

GHSA-3jch-9qgp-4844 is a memory corruption vulnerability in flatbuffers, published on 31 Oct 2021. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Code generated by flatbuffers' compiler is `unsafe` but not marked as such.
See https://github.com/google/flatbuffers/issues/6627 for details.

For example, if generated code is used to decode malformed or untrusted input,
undefined behavior (and thus security vulnerabilities) is possible even without
the use of the `unsafe` keyword, [violating the the meaning of "safe"](https://doc.rust-lang.org/std/keyword.unsafe.html#the-different-meanings-of-unsafe) code;

All users that use generated code by `flatbuffers` compiler are recommended to:
1. not expose flatbuffer generated code as part of their public APIs
2. audit their code and look for any usage of `follow`, `push`, or any method that uses them
   (e.g. `self_follow`).
3. Carefully go through the crates' documentation to understand which "safe" APIs are not
   intended to be used.

## Which versions are affected by GHSA-3jch-9qgp-4844?

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


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

## How do I fix GHSA-3jch-9qgp-4844?

Upgrade flatbuffers to 22.9.29 or later.

## Is GHSA-3jch-9qgp-4844 being exploited?

There is no known exploitation of GHSA-3jch-9qgp-4844 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-3jch-9qgp-4844 and fix it if it is affected.

What it is: GHSA-3jch-9qgp-4844 is a memory corruption vulnerability in flatbuffers, published on 31 Oct 2021. 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-3jch-9qgp-4844 in the wild and no public exploit code.

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

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-3jch-9qgp-4844/ (Markdown: https://insights.sbomify.com/GHSA-3jch-9qgp-4844/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-3jch-9qgp-4844

---
From sbomify Insights: https://insights.sbomify.com/GHSA-3jch-9qgp-4844/
Summaries are generated and may contain mistakes; the official description above is the record.
