# GHSA-5jfw-35xp-5m42: Buffer length underflow in LoginPacket causing unchecked exceptions to be thrown

> A malicious client can crash the PocketMine-MP server by sending a crafted login packet with a negative buffer length, causing an unhandled exception.

- **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:** 5 Apr 2022

## What is GHSA-5jfw-35xp-5m42?

GHSA-5jfw-35xp-5m42 is a vulnerability in pocketmine/bedrock-protocol, published on 5 Apr 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

### Impact
`LoginPacket` uses `BinaryStream->getLInt()` to read the lengths of JSON payloads it wants to decode. Unfortunately, `BinaryStream->getLInt()` returns a signed integer, meaning that a malicious client can craft a packet with a large uint32 value for payload buffer size (which would be interpreted as a negative signed int32), causing `BinaryStream->get()` to throw an exception.

In the context of PocketMine-MP, this leads to a server crash when the vulnerability is exploited.

### Patches
e3fce7632b94e83fd6a518a87dcaf6a11681c4ac

### Workarounds
This can be worked around by registering a custom `LoginPacket` implementation into `PacketPool` which overrides [this code](https://github.com/pmmp/BedrockProtocol/blob/47532c95ea37d5f0365b23f734d70d943ff95295/src/LoginPacket.php#L54) to patch it.

### For more information
* Email us at [team@pmmp.io](mailto:team@pmmp.io)

## Which versions are affected by GHSA-5jfw-35xp-5m42?

2 open source packages ship an affected version, including pocketmine/bedrock-protocol.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `pocketmine/bedrock-protocol` | Packagist | All versions | 8.0.2 |
| `pocketmine/bedrock-protocol` | Packagist | All versions | 8.0.2 |

## How do I fix GHSA-5jfw-35xp-5m42?

Upgrade pocketmine/bedrock-protocol to 8.0.2 or later.

## Is GHSA-5jfw-35xp-5m42 being exploited?

There is no known exploitation of GHSA-5jfw-35xp-5m42 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-5jfw-35xp-5m42 and fix it if it is affected.

What it is: GHSA-5jfw-35xp-5m42 is a vulnerability in pocketmine/bedrock-protocol, published on 5 Apr 2022. 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-5jfw-35xp-5m42 in the wild and no public exploit code.

Affected packages and fixed versions:
- pocketmine/bedrock-protocol (Packagist): affected all versions; fixed in 8.0.2
- pocketmine/bedrock-protocol (Packagist): affected all versions; fixed in 8.0.2

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-5jfw-35xp-5m42/ (Markdown: https://insights.sbomify.com/GHSA-5jfw-35xp-5m42/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-5jfw-35xp-5m42

---
From sbomify Insights: https://insights.sbomify.com/GHSA-5jfw-35xp-5m42/
Summaries are generated and may contain mistakes; the official description above is the record.
