indygreg / indygreg/python-zstandard

ZstdDecompressor.decompress: excessive allocation (crash) on 13-byte malformed frame (decompressor.c:335); should raise ZstdError

Open
#332 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
642
Forks
116
Avg merge
1d 14h
Merged PRs (30d)
5

Description

## Repo
[indygreg/python-zstandard](https://github.com/indygreg/python-zstandard)

## Summary
`ZstdDecompressor().decompress()` pre-allocates the full Frame_Content_Size (FCS) from the frame header WITHOUT capping; a 13-byte malformed frame declaring a corrupt FCS makes it call `PyBytes_FromStringAndSize` for a ~1.1 TB buffer at `c-ext/decompressor.c:335`, causing an ASan **allocation-size-too-big ABORT** (in production: a huge `MemoryError`) — i.e. a crash/DoS on a tiny untrusted decompression input, rather than the documented `ZstdError`.

## Trigger (13 bytes)
hex: `28b52ffde06c06060663636363`

## Evidence
ASan (binding C-ext built with `-fsanitize=address`):
```
ERROR: AddressSanitizer: requested allocation size 0x66c6c6c00000121 exceeds maximum supported size
#3 PyBytes_FromStringAndSize
#4 Decompressor_decompress c-ext/decompressor.c:335
SUMMARY: AddressSanitizer: allocation-size-too-big
ABORTING
```

## Expected
The Frame_Content_Size field of a malformed/short frame must not cause an over-allocation; the decompressor should reject such input (raise `ZstdError` / cap the buffer & grow dynamically), as single-shot malloc of an attacker-controlled FCS is unsafe (CWE-789).

## Note
This binding C-ext path is NOT covered by OSS-Fuzz (only upstream zstd core is) and has no advisory.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at c-ext/decompressor.c:335 and reproduce the issue with the supplied 13-byte malformed frame. Trace how the frame content size reaches allocation and how decompression errors become ZstdError; done means malformed input is rejected without an oversized allocation and regression coverage verifies the failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.