Browser Handling of Broken and Truncated JPEGs

When network instability interrupts an image download, modern web browsers do not simply fail to display the asset; instead, they employ resilient decoding routines to render as much visual data as possible. This article details the underlying mechanisms browsers and image libraries use to handle missing end-of-file markers, the visual differences between truncated baseline and progressive JPEGs, how decoders conceal errors, and the network-level implications of incomplete data streams.

JPEG Structure and the Missing End-of-Image Marker

A standard JPEG data stream begins with a Start of Image (SOI) marker (0xFFD8) and concludes with an End of Image (EOI) marker (0xFFD9). Between these boundaries lie metadata headers, quantization tables, Huffman tables, and scan data encoded in Minimum Coded Units (MCUs).

When a network connection drops, the stream terminates prematurely without the final EOI marker. Underlying browser graphics engines (such as Skia in Chromium, Core Graphics in WebKit, or MozJPEG/libjpeg-turbo in Gecko) monitor incoming bytes. Upon detecting a connection close without an EOI marker, the decoder treats the stream as truncated, synthesizes an internal EOI marker, and attempts to parse all successfully received MCUs up to the point of disconnection.

Baseline vs. Progressive Stream Truncation

The visual outcome of a truncated image depends heavily on the compression mode used during encoding.

Baseline JPEGs

Baseline JPEGs store scanlines sequentially from top to bottom.

Progressive JPEGs

Progressive JPEGs store image data in multiple full-frame passes, gradually refining frequency coefficients and color detail.

Error Concealment and Entropy Decoding Failures

Network instability can cause bit corruption rather than a clean cut-off. If byte corruption alters the entropy-coded segments (the Huffman or arithmetic data), decoders face desynchronization.

Network Lifecycle and Cache Treatment

The browser's network stack coordinates with the renderer to decide whether a broken image should be accepted or retried.