Corrupt JPG and Canon .CR2 Files

By | December 9, 2016

The following is a corrupt JPG file repair example of pictures taken during an Indian wedding. The pictures were taken using a Canon 5D Mark III. The memory card was removed from the camera, and using a card reader they were transferred to a PC. Corruption was discovered when it was already too late to retrieve the original files from the card.

  • In case you do not have separate JPG files, JpegDigger can extract JPEGs from RAW files of a number of camera manufacturers.
  • If you need to recover CR2 files from a memory card you can use JPEG Recovery LAB. I recommend you try it even if other photo recovery software gave you corrupt files. JPEG Recovery LAB includes some unique technology to recover corrupt, fragmented files.

Both the RAW .CR2 files as the JPEG preview files are corrupt.

Corrupt RAW .cr2 file

Corrupt RAW .cr2 file

Corrupt JPG

Corrupt JPG

Corruption in the .CR2 file looks even more dramatic than the corruption in the JPG file! At this point I don’t know enough on the internals of RAW files, but the amount of actual damage does not necessarily correlate with the amount of observable damage.

The corrupt JPG

Unfortunately I can not help with the Canon .CR2 file, so I will concentrate on the JPEG. Please note that the examples here are not the originals, I am displaying resized files.

Corrupt JPG. Pixel shift and color shift

Now, compared to previous JPGs I repaired, the damage looks ‘less’ severe. However, this turns out to be a repair I have invested more time in then any of the ones before. And this is without taking into account that I had to fix several issues I ran into using my JPEG Repair Toolkit. (Buffers too small for files > 5 MB).

The repairs I did so far had very distinct areas where ‘healthy data’ is separated from ‘corrupt data’. Because of that it is harder to determine my ‘angle of attack’, to pinpoint the exact spot from where the corruption starts.

As a result it takes a lot of trial and error; edit byte stream, see how changes reflect the image, change bytes back, etc etc..


You can use any binary file editor to do this. Change data, save the file, open it in an image viewer and see what changed. However make it easier to verify the effects of adding, removing and modifying data one of the tools in the JPEG Repair Toolkit is a combined binary editor / JPG viewer. Also, rather than working on the file itself, the tools works with a byte array which is an exact copy of the original file. That data is then displayed as an image.

After a considerable amount of attempts I have this:

Corrupt JPG repair first phase. Color shift towards end of image

The grey blocks marked by the arrow aren’t the problem. I get those with each repair and they are inevitable. I can easily fix those using a process called ‘inpainting’. Inpainting uses surrounding data to fill in an area. However if you look closer there is a shift in colors 80% (or so) into the image. This nicely illustrates how even a byte of corruption effects all data that follows that byte.

The (almost) final result

It takes me over an hour of experimentation to arrive at this result:

Corrupt JPG almost repaired

The color shift is fixed. Minor damage remains, but you can consider this a presentable image. The only thing left to is to find and fix tiny blocks of grey pixels that are the result of the repairs.

Leave a Reply

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