# CVE-2022-36078: Slice Memory Allocation with Excessive Size Value in binary

> Attackers can cause denial of service by triggering excessive memory allocation when parsing untrusted data with the binary library.

- **Severity:** High 8.8 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 2 Sep 2022
- **Updated:** 22 Apr 2025
- **Also known as:** GHSA-4p6f-m4f9-ch88, GO-2022-0963

## What is CVE-2022-36078?

CVE-2022-36078 is a high-severity denial of service vulnerability in gagliardetto binary, published on 2 Sep 2022. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.

### Official description

Binary provides encoding/decoding in Borsh and other formats. The vulnerability is a memory allocation vulnerability that can be exploited to allocate slices in memory with (arbitrary) excessive size value, which can either exhaust available memory or crash the whole program. When using `github.com/gagliardetto/binary` to parse unchecked (or wrong type of) data from untrusted sources of input (e.g. the blockchain) into slices, it's possible to allocate memory with excessive size. When `dec.Decode(&val)` method is used to parse data into a structure that is or contains slices of values, the length of the slice was previously read directly from the data itself without any checks on the size of it, and then a slice was allocated. This could lead to an overflow and an allocation of memory with excessive size value. Users should upgrade to `v0.7.1` or higher. A workaround is not to rely on the `dec.Decode(&val)` function to parse the data, but to use a custom `UnmarshalWithDecoder()` method that reads and checks the length of any slice.

Weakness: CWE-1284 (Improper Validation of Specified Quantity in Input), CWE-789 (Memory Allocation with Excessive Size Value)

## Which versions are affected by CVE-2022-36078?

3 open source packages ship an affected version, including github.com/gagliardetto/binary. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `github.com/gagliardetto/binary` | Go | All versions | 0.7.1 |
| `github.com/gagliardetto/binary` | Go | All versions | 0.7.1 |
| `github.com/gagliardetto/binary` | Go | All versions | 0.7.1 |

Products: Binary Project Binary.

## How do I fix CVE-2022-36078?

Upgrade github.com/gagliardetto/binary to 0.7.1 or later.

## Is CVE-2022-36078 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2022-36078 exists.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2022-36078 and fix it if it is affected.

What it is: CVE-2022-36078 is a high-severity denial of service vulnerability in gagliardetto binary, published on 2 Sep 2022. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Exploitation: It is not confirmed as exploited in the wild, but public exploit code for CVE-2022-36078 exists.

Affected packages and fixed versions:
- github.com/gagliardetto/binary (Go): affected all versions; fixed in 0.7.1
- github.com/gagliardetto/binary (Go): affected all versions; fixed in 0.7.1
- github.com/gagliardetto/binary (Go): affected all versions; fixed in 0.7.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/CVE-2022-36078/ (Markdown: https://insights.sbomify.com/CVE-2022-36078/index.md)
```

## Sources

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

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