Data Recovery & FilesTechnology

How to Repair a JPG with an Invalid SOS Marker or Corrupt Header Error

Admin
How to Repair a JPG with an Invalid SOS Marker or Corrupt Header Error

Your photo viewer refuses the file completely: “invalid SOS marker,” “corrupt header,” or a flat “cannot open this file.” Unlike a photo that loads halfway, this one will not even start — yet there is a real chance the picture itself is almost entirely intact behind a few damaged bytes at the front.

A JPG file is two things: a header describing how to decode it, and the compressed image data that follows. Header damage is the best kind of JPG damage to have, because the header can be borrowed from another photo taken by the same camera with the same settings. That donor-header technique is the heart of this repair.

Quick Answer

Work only on a copy of the file. The standard fix is to take the header from a healthy photo shot on the same camera at the same resolution (a “donor” file) and graft it onto your damaged file in place of its corrupt header, using a hex editor or a specialised tool such as JPEG-Repair. Where the header ends is marked by the SOS marker (FF DA in hex) — everything after it is your photo data, which is usually untouched. If the damage extends into the data itself, repair tools can still often render a partial image.

What the Error Actually Means

JPGs are organised into segments, each introduced by a marker: two bytes starting with FF. The file opens with FFD8 (start of image), passes through segments describing colour tables and frame dimensions, and reaches FFDA — Start of Scan, the SOS marker — after which the actual compressed picture data begins. Viewers reporting an “invalid SOS marker” or a corrupt header are telling you the damage sits in that opening region: a marker is wrong, a length field is nonsense, or the structure is scrambled. Common causes: the file was recovered imperfectly, a card glitch flipped early bytes, or a transfer was interrupted at the very start.

The hopeful part: header bytes are a tiny fraction of the file. A 6MB photo might have a header of a few kilobytes. If the rot is confined there, the photo is recoverable almost perfectly.

The Donor-Header Repair, Step by Step

  1. Duplicate the damaged file and rename the copy clearly (photo-repair-attempt.jpg). The original never gets edited.
  2. Find a donor photo: an unedited JPG from the same camera or phone, same resolution and orientation, ideally shot around the same time with the same settings. Photos from a different model can occasionally work but usually carry mismatched tables.
  3. Use a repair tool if you prefer guidance. JPEG-Repair (from the DiskTuna site, maker of the JPEG Repair Toolkit) automates donor-header grafting and shows previews as you work — strongly recommended over raw hex editing for a first attempt.
  4. Or do it manually in a hex editor (HxD on Windows is free): open both files, find the SOS marker FF DA in the donor, and note where the scan data begins — the marker is followed by a short segment header, typically 10–14 bytes, ending just before the entropy-coded data. Copy everything from the start of the donor up to that point, and overwrite the same region in your damaged copy. Save, and open the result.
  5. Check the result carefully. A successful graft opens as a complete photo, sometimes with a colour cast if the donor’s tables differed slightly. Scroll the whole image at 100% to confirm the data section is healthy all the way down.
  6. If the top renders but the image degrades partway, the damage extends into the scan data. Repair tools can sometimes reconstruct up to the damage; beyond that point you are in the territory of our guide to recovered JPGs that open halfway with grey bottoms.

Simpler Things to Try First

  • Open it in different software. Some viewers are strict, others forgiving. Try a browser, a different image editor, and an online viewer before concluding the header is truly broken.
  • Check the file extension and size. A .jpg that is actually a PNG or HEIC in disguise (renamed by a transfer tool) triggers header errors in strict apps. A file size of 0 bytes, however, means there is nothing to repair.
  • Re-copy the file from its source. If the corruption came from a bad transfer rather than the original media, a fresh copy from the card or phone may be flawless — always the cheapest repair when the source still exists.
  • Run a validation pass. Tools like JHOVE or JPEG-Info style validators describe exactly which segment fails, which tells you whether header surgery is even the right operation.

Common Mistakes to Avoid

  • Editing the only copy. Hex editing is unforgiving and undo is not guaranteed. Originals stay untouched; experiments happen on duplicates.
  • Using a donor from a different camera. Mismatched quantisation and Huffman tables produce psychedelic colour garbage or a file that still will not open. Same camera, same resolution, same era.
  • Assuming one graft fixes everything. If colours look plausible but wrong, try a different donor from the same set — table variations between shooting modes are real.
  • Uploading precious photos to random “repair” websites. Some are fine; some retain uploads. For personal photos, prefer local tools where your files never leave your machine.

Diagnose Before You Operate

Thirty seconds of diagnosis saves an hour of wrong surgery. First, ask where the file came from: a file corrupted during recovery may have a healthy twin in a second recovery pass, while a file corrupted on the card itself is the only version there is. Second, check whether the damage is in the EXIF header specifically — photos whose metadata segment was mangled (for instance by a buggy editor) sometimes open after simply stripping and rebuilding the metadata with a tool like ExifTool, without touching the image header at all. Third, note the exact error from two different viewers; their disagreement maps the damage. A viewer that shows a garbled top strip before failing is telling you the header is nearly right, while instant refusal in everything suggests the opening markers are scrambled.

Also confirm the file is really a JPG. Cameras and phones produce HEIC, PNG screenshots and the occasional TIFF, and a mislabelled extension produces header errors that no donor graft will cure — renaming the file to its true format sometimes “repairs” it in one keystroke. File-inspection tools report the real format from the first bytes regardless of the name.

Conclusion

An invalid SOS marker sounds fatal, but it usually means a few kilobytes of header are damaged while megabytes of photo survive behind them. Borrow a header from a same-camera donor, graft it onto a copy with a repair tool or a careful hex edit, and the photo often returns whole. And as always in recovery work: the original file is sacred — experiment on copies only.

Frequently Asked Questions

What exactly is the SOS marker?

It is the Start of Scan marker (bytes FF DA) that separates a JPG’s header from its compressed image data. Errors naming it mean the viewer could not find or trust the header structure leading to the scan data.

Where do I find a good donor file?

Your own photo library: any healthy, unedited JPG from the same camera or phone at the same resolution. Burst siblings of the damaged photo are perfect donors.

The repaired photo opened but the colours are wrong. Now what?

Try a different donor — ideally from the same shooting session — because colour and compression tables vary by mode and settings. A close-but-wrong result still proves your image data is intact, which is the main battle.

Can ExifTool fix a corrupt header?

ExifTool can repair some structural metadata issues and reports warnings about others, but a destroyed header generally needs the donor graft or a dedicated repair tool. ExifTool is excellent for diagnosis either way.

Is the repair permanent and safe to archive?

Yes — once the grafted file opens correctly, it is a normal JPG. Archive it alongside (never instead of) the damaged original, with a note about what was done.

Admin

Passionate about the intersection of style and storytelling. I simplify fashion trends and industry news into easy-to-follow advice, helping you stay stylish and informed in the fast-paced world of fashion.

Leave a Reply

Your email address will not be published. Required fields are marked *