# CVE-2020-26243: Memory leak in nanopb

> Attackers can cause memory leaks in nanopb by sending crafted messages with specific oneof structures, leading to resource exhaustion.

- **Severity:** High 7.5 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 25 Nov 2020
- **Updated:** 4 Aug 2024
- **Also known as:** DEBIAN-CVE-2020-26243, GHSA-85rr-4rh9-hhwh, PYSEC-2026-684, UBUNTU-CVE-2020-26243

## What is CVE-2020-26243?

CVE-2020-26243 is a high-severity memory corruption vulnerability in nanopb, published on 25 Nov 2020. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Nanopb is a small code-size Protocol Buffers implementation. In Nanopb before versions 0.4.4 and 0.3.9.7, decoding specifically formed message can leak memory if dynamic allocation is enabled and an oneof field contains a static submessage that contains a dynamic field, and the message being decoded contains the submessage multiple times. This is rare in normal messages, but it is a concern when untrusted data is parsed. This is fixed in versions 0.3.9.7 and 0.4.4. The following workarounds are available: 1) Set the option `no_unions` for the oneof field. This will generate fields as separate instead of C union, and avoids triggering the problematic code. 2) Set the type of the submessage field inside oneof to `FT_POINTER`. This way the whole submessage will be dynamically allocated and the problematic code is not executed. 3) Use an arena allocator for nanopb, to make sure all memory can be released afterwards.

Weakness: CWE-20 (Improper Input Validation), CWE-119 (Improper Restriction of Operations within the Bounds of a Memory Buffer)

## Which versions are affected by CVE-2020-26243?

5 open source packages ship an affected version, including nanopb. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `nanopb` | PyPI | From 0.3.2 | 0.3.9.7, 0.4.4 |
| `nanopb` | PyPI | From 0.3.2 | 0.3.9.7 |
| `nanopb` | PyPI | From 0.3.2 | 0.3.9.7 |
| `nanopb` | PyPI | From 0.4.0 | 0.4.4 |
| `nanopb` | PyPI | From 0.4.0 | 0.4.4 |

Products: Nanopb Project Nanopb.

## How do I fix CVE-2020-26243?

Upgrade nanopb to a fixed version for your release line: 0.3.9.7 or 0.4.4.

## Is CVE-2020-26243 being exploited?

There is no known exploitation of CVE-2020-26243 in the wild and no public exploit code.

## Other vulnerabilities in nanopb

- [CVE-2014-125106](https://insights.sbomify.com/CVE-2014-125106/): Integer overflow in n/a (critical 9.8)
- [CVE-2021-21401](https://insights.sbomify.com/CVE-2021-21401/): Invalid free() call in Nanopb (high 7.1)
- [CVE-2020-5235](https://insights.sbomify.com/CVE-2020-5235/): Out-of-memory condition in Nanopb is potentially exploitable (medium 6.5)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2020-26243 and fix it if it is affected.

What it is: CVE-2020-26243 is a high-severity memory corruption vulnerability in nanopb, published on 25 Nov 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 CVE-2020-26243 in the wild and no public exploit code.

Affected packages and fixed versions:
- nanopb (PyPI): affected from 0.3.2; fixed in 0.3.9.7, 0.4.4
- nanopb (PyPI): affected from 0.3.2; fixed in 0.3.9.7
- nanopb (PyPI): affected from 0.3.2; fixed in 0.3.9.7
- nanopb (PyPI): affected from 0.4.0; fixed in 0.4.4
- nanopb (PyPI): affected from 0.4.0; fixed in 0.4.4

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-2020-26243/ (Markdown: https://insights.sbomify.com/CVE-2020-26243/index.md)
```

## Sources

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

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