# GHSA-5x36-7567-3cw6: partial_sort contains Out-of-bounds Read in release mode

> Attackers can trigger out-of-bounds reads in release builds, potentially exposing sensitive memory contents.

- **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:** 20 Feb 2023
- **Also known as:** RUSTSEC-2023-0016

## What is GHSA-5x36-7567-3cw6?

GHSA-5x36-7567-3cw6 is a memory corruption vulnerability in partial_sort, published on 20 Feb 2023. 

### Official description

Affected versions of this crate were using a debug assertion to validate the `last` parameter of `partial_sort()`. This would allow invalid inputs to cause an out-of-bounds read instead of immediately panicking, when compiled without debug assertions.

All writes are bounds-checked, so the out-of-bounds memory access is read-only. This also means that the first attempted out-of-bounds write will panic, limiting the possible reads.

The accessible region is further limited by an initial bounds-checked read at `(last / 2) - 1`, i.e., it is proportional to the size of the vector.

This bug has been fixed in v0.2.0.

## Which versions are affected by GHSA-5x36-7567-3cw6?

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


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

## How do I fix GHSA-5x36-7567-3cw6?

Upgrade partial_sort to 0.2.0 or later.

## Is GHSA-5x36-7567-3cw6 being exploited?

There is no known exploitation of GHSA-5x36-7567-3cw6 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-5x36-7567-3cw6 and fix it if it is affected.

What it is: GHSA-5x36-7567-3cw6 is a memory corruption vulnerability in partial_sort, published on 20 Feb 2023. 
Exploitation: There is no known exploitation of GHSA-5x36-7567-3cw6 in the wild and no public exploit code.

Affected packages and fixed versions:
- partial_sort (crates.io): affected all versions; fixed in 0.2.0
- partial_sort (crates.io): affected all versions; fixed in 0.2.0
- partial_sort (crates.io): affected from 0.0.0-0; fixed in 0.2.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-5x36-7567-3cw6/ (Markdown: https://insights.sbomify.com/GHSA-5x36-7567-3cw6/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-5x36-7567-3cw6

---
From sbomify Insights: https://insights.sbomify.com/GHSA-5x36-7567-3cw6/
Summaries are generated and may contain mistakes; the official description above is the record.
