When a photo or screenshot refuses to open in Windows Photos, macOS Preview, or Photoshop, most people assume the pixels are gone forever. In practice, a large share of "corrupted" images still have intact compressed pixel streams — only the framing markers, metadata blocks, or chunk checksums broke during an interrupted transfer or SD card recovery.

Because photos and design assets are often private, uploading them to a cloud repair site just to check whether a header is fixable makes no sense. Below is a binary-level breakdown of how JPG/JPEG and PNG corruption actually happens, and how we built a 100% client-side Rust + WebAssembly engine to diagnose and repair them directly in browser memory.

1. JPEG / JPG Framing: Why FF D8, APP1, and FF D9 Matter

A valid .jpg / .jpeg bitstream is a chain of two-byte markers:

FF D8 Start Of Image (SOI) FF E0 / FF E1 APP0 (JFIF) / APP1 (EXIF, GPS, XMP metadata) FF DB Define Quantization Table (DQT) FF C0 / FF C2 Start Of Frame (SOF0 baseline / SOF2 progressive) FF C4 Define Huffman Table (DHT) FF DA ... Start Of Scan (SOS) + compressed entropy data FF D9 End Of Image (EOI) 

Three failure modes account for most recoverable JPG errors:

  1. Leading junk bytes before FF D8 FF: File carvers like PhotoRec or broken HTTP downloads frequently leave stray header bytes before the SOI marker, causing Photoshop and OS viewers to report "Not a JPEG file" or "invalid JPEG marker".
  2. Malformed APP1 EXIF segments: A corrupted length prefix inside an EXIF/XMP block trips strict parsers even when the quantization tables and scan data right after it are completely healthy.
  3. Missing FF D9 End-Of-Image trailer: Truncated writes cut off the final two bytes. Appending FF D9 lets decoders render every surviving scanline cleanly.

You can test JPEG marker scanning and lossless EXIF stripping directly in your tab with the FileRepair JPG / JPEG header fixer (or inspect both JPG and PNG photos together on https://filerepair.app/repair-image/).

2. PNG Chunk Anatomy: Why a Single Flipped Bit Breaks the Whole File

Unlike JPEG's marker stream, PNG uses a strict 8-byte file signature followed by length-prefixed chunks:

Signature: 89 50 4E 47 0D 0A 1A 0A (\x89PNG\r\n\x1a\n) Chunk: [4-byte Length] [4-byte Type] [Data...] [4-byte IEEE CRC32] Critical: IHDR -> (PLTE) -> IDAT... -> IEND 

That 8-byte signature was deliberately designed to catch newline translation bugs (e.g., FTP ASCII mode converting 0D 0A to 0A). Even more strictly, libpng, browsers, and Figma verify the IEEE CRC32 on every single chunk:

  • If a single bit flips inside IHDR or an ancillary chunk (tEXt, iCCP, pHYs), libpng aborts with CRC error in chunk.
  • If a download truncates right before the final 12-byte IEND chunk (00 00 00 00 49 45 4E 44 AE 42 60 82), strict viewers refuse to render the surviving IDAT stream.

Walking the chunks in Rust/WASM, restoring the 8-byte header, recomputing IEEE CRC32 values, dropping malformed non-critical chunks, and appending IEND recovers a surprising number of broken PNG exports in milliseconds. You can run this locally on FileRepair's browser-side PNG fixer.

3. The Hidden Culprit: Wrong or Missing File Extensions

A huge percentage of "Windows Photos doesn't support this file format" errors aren't corruption at all — they are extension mismatches:

  • A WebP or HEIC image saved with a .jpg extension
  • A PNG renamed to .jpeg
  • An email or messaging attachment downloaded as download, IMG_2026, .bin, .dat, or .tmp

Instead of trusting the filename, inspecting raw binary magic bytes (and container internals like ZIP entries or ISO BMFF ftyp brands) reveals the true format instantly. Checking Shannon entropy and zero-byte ratio at the same time also catches unrecoverable all-zero (0x00) files before you waste time trying tools.

For extensionless or misnamed files across 40+ formats, we expose the same magic-byte detector on the FileRepair unknown file format identifier.

Verifying 100% On-Device Privacy

All diagnostics, header repairs, and metadata scrubbing on FileRepair run inside a local Web Worker backed by Rust + WebAssembly:

  1. Open any tool page (e.g., https://filerepair.app/repair-jpg/ or https://filerepair.app/repair-png/).
  2. Disconnect Wi-Fi or open DevTools → Network tab.
  3. Drop a local file — 0 KB is ever transmitted to a server.

Hopefully these byte-level notes save someone from throwing away a recoverable photo or writing a one-off hex-editor script!