How Decompression Bombs Crash Browsers and Servers With a 50 KB Image File

Understand the mathematics of image pixel floods, why file.size checks fail against DEFLATE compression bombs, and how pre-flight binary header sniffing gates memory.

How Decompression Bombs Crash Browsers and Servers With a 50 KB Image File
Table of Contents
Key Takeaways
  • A decompression bomb is a tiny compressed file on disk (often under 50 KB) that inflates into tens of gigabytes of raw uncompressed RGBA bitmap pixels when decoded.
  • Naive upload validators that only check file.size are blind to pixel floods because solid-color image data compresses with near-infinite efficiency under DEFLATE.
  • Attempting to render a 60,000 x 60,000 pixel image crashes browser tabs, freezes mobile devices, and triggers Out-of-Memory (OOM) fatal kills on backend servers.
  • Effective protection requires pre-flight binary header sniffing: reading IHDR (PNG) or SOF0 (JPEG) chunks in the first 256 bytes to enforce strict megapixel ceilings before memory allocation.
  • PoofShare enforces a 36-megapixel dimension gate client-side and at the edge, rejecting pixel floods in less than 0.2 milliseconds with zero canvas decoding.

The Mathematics of a DEFLATE Pixel Flood

When developers think about Denial of Service (DoS) attacks, they typically imagine high-volume network floods. Yet one of the most asymmetric vectors in web security requires only a single HTTP request containing a 50 KB image file.

This attack is known as an image decompression bomb or a pixel flood.

Consider how image compression algorithms interact with memory buffers.

PNG and WebP images rely on DEFLATE compression: combining LZ77 substitution and Huffman coding to find repeating patterns. If you compress an image where millions of pixels share the same 32-bit RGBA color (such as solid black #000000), DEFLATE stores a tiny instruction: "Repeat this 4-byte sequence 3.6 billion times."

Input File on Disk:  50 Kilobytes (DEFLATE compressed)
Dimensions:          60,000 pixels wide x 60,000 pixels tall
Total Pixel Count:   3,600,000,000 pixels
Memory Requirement:  3.6 billion pixels x 4 bytes (RGBA) = 14.4 Gigabytes RAM

The compression ratio exceeds 288,000 to 1. On disk, the operating system sees a featherweight 50 KB file. But the moment an application passes that buffer to an image decoding library (such as libpng, ImageMagick, or an HTML5 Canvas context), the decoder allocates contiguous RAM for every uncompressed pixel.

The Decompression Bomb Memory Explosion Ratio
The Decompression Bomb Memory Explosion Ratio

Why Checking file.size Alone Completely Fails

The root cause of decompression bomb vulnerabilities is naive upload filtering:

// Vulnerable validation pattern
if (uploadedFile.size > 10 * 1024 * 1024) {
  throw new Error("File exceeds maximum allowed size of 10 MB");
}

This logic rests on the mistaken assumption that physical file size correlates with memory consumption. For compressed formats, that assumption is dangerously false:

  1. The Size Gate Passes: The server sees 50 KB is below the 10 MB limit.
  2. Buffer Allocation Begins: The app hands the stream to an image tool to generate thumbnails or scrub metadata.
  3. Memory Spike: The runtime requests an instant 14.4 GB memory allocation from the OS kernel.
  4. Catastrophic Failure: On a server with 2 GB to 8 GB of RAM, the Linux OOM killer triggers immediately, terminating the worker process and dropping connections.
  5. Client Freeze: If delivered to a browser, the tab consumes all device memory, freezing or crashing.
WARNING
Metadata Strippers Can Trigger the Bomb: Even security-conscious hosts attempting to scrub EXIF metadata are vulnerable. If your metadata stripping routine decodes image rasters before checking dimension headers, the server crashes during sanitization itself.

Pre-Flight Binary Header Sniffing

Stopping a decompression bomb requires identifying its dimensions before memory is allocated.

Raster image specifications store dimensions near the start of the binary stream. By inspecting the first 256 to 512 bytes of a file, an application reads canvas dimensions in under 0.2 milliseconds without running DEFLATE decompression routines.

Pre-Flight Binary Header Sniffing
Pre-Flight Binary Header Sniffing

Reading PNG IHDR Dimensions

In a valid PNG file, the first 8 bytes contain the PNG signature (\x89PNG\r\n\x1a\n), followed by the IHDR chunk:
  • Bytes 00-07: PNG Signature
  • Bytes 08-11: Chunk length (\x00\x00\x00\x0d = 13 bytes)
  • Bytes 12-15: Chunk type (IHDR)
  • Bytes 16-19: Image Width (32-bit unsigned big-endian)
  • Bytes 20-23: Image Height (32-bit unsigned big-endian)

Reading bytes 16 through 23 provides exact canvas dimensions instantly. If width multiplied by height exceeds your threshold, the upload is rejected before memory allocation occurs.

Reading JPEG SOF0 Markers

In JPEG files, dimensions are stored in the Start of Frame segment (SOF0 marker 0xFF, 0xC0):
  • Scan the byte stream looking for marker prefix 0xFF.
  • At 0xFF, 0xC0, skip the 2-byte segment length and 1-byte precision indicator.
  • Read the next 2 bytes as a 16-bit big-endian integer for Height.
  • Read the subsequent 2 bytes as a 16-bit big-endian integer for Width.

Because header bytes are positioned near the top of the stream, edge workers only need to inspect the first chunk of an incoming stream.

The 36-Megapixel Dimension Gate

To establish predictable resource consumption, image hosts enforce dimension limits and aggregate megapixel ceilings.

At PoofShare, we implement a strict 36-megapixel dimension gate:

  • Maximum Dimensions: 8,192 x 8,192 pixels
  • Maximum Aggregate Pixels: 36,000,000 pixels

A 36-megapixel image provides ample resolution for 4K and 8K captures, requiring ~144 MB of uncompressed RAM (36,000,000 x 4 bytes) that modern devices handle effortlessly.

In contrast, a 60,000 x 60,000 pixel bomb claims over 14 GB of RAM. Our pre-flight binary sniff catches excessive dimensions in the first packet, returning HTTP 413 Payload Too Large before the full payload is received.

Protecting Your Applications

If you build web applications accepting image uploads, implement pre-flight dimension validation:

  1. Client-Side Pre-Flight Check: In the browser, read the first 512 bytes of a dropped File via file.slice(0, 512).arrayBuffer(). Parse IHDR or SOF0 dimensions in JavaScript before calling URL.createObjectURL() or drawing to Canvas.
  2. Edge Stream Interception: At your reverse proxy or edge API gateway, inspect incoming chunk headers. If dimensions exceed 8,192 pixels or 36 megapixels, terminate the stream immediately.
  3. Limit SVG ViewBox Attributes: While raster bombs exploit pixel buffers, vector graphics exploit XML dimensions. Ensure your SVG parser validates viewBox coordinates, as discussed in our deep dive on why SVG files are executable code.

Pairing pre-flight header validation with client-side PNG-8 quantization delivers fast image transfers while protecting infrastructure. Review our zero-knowledge data retention guarantees in our Privacy Policy and learn more on our About Page.

What is the difference between a zip bomb and an image decompression bomb?

A zip bomb is an archive containing nested compressed archives expanding into petabytes of dummy data when unzipped. An image decompression bomb uses DEFLATE inside a single image file (like PNG) to force decoders to allocate gigabytes of bitmap RAM during rendering.

Can a decompression bomb permanently damage my computer?

No. A decompression bomb will not damage physical hardware. However, it exhausts available RAM, freezing the OS, terminating background apps, and crashing browser tabs. On production servers, it forces kernel panics or worker restarts.

Why can't image viewing software stream pixels without allocating full RAM?

Operating system rendering engines and browser Canvas contexts require a contiguous 2D pixel buffer in memory to paint pixels to screen coordinates, handle alpha blending, and apply GPU shaders. Without that full buffer, zooming and rendering cannot function.

What maximum image resolution does PoofShare allow?

PoofShare allows images up to 8,192 pixels in width or height, with an upper ceiling of 36 megapixels (sufficient for full 8K screen captures). Any image exceeding these dimensions is rejected at the binary header level before decoding begins.

PS

PoofShare Team

Dedicated to building zero-knowledge, ephemeral hosting systems and sharing practical technical guides on privacy.

Link copied to clipboard!