Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add decompression size limit to FITS gzip decoder#9475

Closed
myagmartseren wants to merge 1 commit into
python-pillow:mainpython-pillow/Pillow:mainfrom
myagmartseren:fix/fits-gzip-decompression-bombmyagmartseren/Pillow:fix/fits-gzip-decompression-bombCopy head branch name to clipboard
Closed

Add decompression size limit to FITS gzip decoder#9475
myagmartseren wants to merge 1 commit into
python-pillow:mainpython-pillow/Pillow:mainfrom
myagmartseren:fix/fits-gzip-decompression-bombmyagmartseren/Pillow:fix/fits-gzip-decompression-bombCopy head branch name to clipboard

Conversation

@myagmartseren

@myagmartseren myagmartseren commented Mar 19, 2026

Copy link
Copy Markdown

Decompression Bomb in FITS Gzip Decoder (DoS)

Summary

FitsGzipDecoder.decode() calls gzip.decompress(self.fd.read()) with no size limit. A crafted FITS file containing a gzip bomb (~100 KB) can decompress to gigabytes, causing OOM / denial of service.

Affected Code

src/PIL/FitsImagePlugin.py, line 131:

value = gzip.decompress(self.fd.read())  # No size limit!

Impact

  • A 135 KB FITS file can force allocation of 64+ MB (485x amplification)
  • Larger bombs easily achieve 1000:1+ ratios (1 MB → 1 GB)
  • Unlike PNG (has MAX_TEXT_CHUNK) and general images (has _decompression_bomb_check), FITS gzip has zero protection

Fix

Add a decompression size limit based on expected image dimensions:

max_expected = self.state.xsize * self.state.ysize * 4
max_decompressed = max(max_expected * 2, 1024 * 1024)
value = gzip.decompress(self.fd.read())
if len(value) > max_decompressed:
    raise ValueError(...)

Classification

  • CWE-409 (Improper Handling of Highly Compressed Data)
  • CVSS 3.1: 7.5 (High) — AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

gzip.decompress() was called without any size limit, allowing a
crafted FITS file with a gzip bomb to cause unbounded memory
allocation (OOM/DoS). Add a limit based on the expected image
dimensions, similar to MAX_TEXT_CHUNK in the PNG decoder.

Security: CWE-409 (Decompression Bomb)
@EricSoroos

Copy link
Copy Markdown

Thanks, please note our security policy: https://github.com/python-pillow/Pillow/blob/main/.github/SECURITY.md

I don't think the fix does what you expect it to do, as you're checking for the length of the data after decompression.

@aclark4life aclark4life changed the title Add decompression size limit to FITS gzip decoder (security) Add decompression size limit to FITS gzip decoder Mar 19, 2026
@aclark4life aclark4life added the 🤖-assisted AI-assisted label Mar 19, 2026
@radarhere

Copy link
Copy Markdown
Member

Thanks for the thought. I agree that this doesn't fix the problem.

I'm reluctant to discuss security problems in public, but I expect that in a week or two, we will create a variation on this.

@radarhere radarhere closed this Mar 19, 2026
@myagmartseren
myagmartseren deleted the fix/fits-gzip-decompression-bomb branch March 29, 2026 07:22
@radarhere

Copy link
Copy Markdown
Member

Pillow 12.2.0 has been released with #9521 as our version of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖-assisted AI-assisted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.