Solved

Opening corrupt jpg files

Posted on 2011-02-18
15
2,104 Views
Last Modified: 2013-11-22
We have a customer whose jpg files have gotten corrupt due to virus issues and need opinions on the best way to recover the files - shows individual files in various sizes, but can't open
0
Comment
Question by:wheeler2162
15 Comments
 
LVL 1

Expert Comment

by:rajwec
Comment Utility
use getdataback ntf softwares or RSTUDIO ..or use recuva its freeware..
0
 

Author Comment

by:wheeler2162
Comment Utility
Thanks very much - will definitely try those - they are different titles than we have tried to date.  Thank you for your prompt reply.
0
 

Author Comment

by:wheeler2162
Comment Utility
Three programs later - no luck - but thanks for the suggestions - they all came up with 0 recoverable.
0
 
LVL 38

Accepted Solution

by:
lherrou earned 125 total points
Comment Utility
wheeler2162,

I'm afraid the prognosis is not good. My experience with corruption taking the form you describe has been that recovery is unlikely to succeed.

Here's a couple of thoughts for you: First of all, here's some other photo recovery software to try: take a look at BadCopy Pro (http://www.jufsoft.com/badcopy/) and PhotoRescue (www.datarescue.com - for both Microsoft Windows and Mac OS). Each of these can deal with corrupted graphics files, and help repair the damaged files. I've had my best success with PhotoRescue, although sometimes images can be fixed in one of these and not the other.

You can also sometimes open corrupted file in applications like CorelDraw (which can sometimes import damaged JPGs. Once the file is imported into Draw it can be exported again as a new fresh JPG) or Photoshop (using RAW mode). For the latter, you need to know the size of the image in pixels. What you do in Photoshop is select File>Open As and in the dialog box choose RAW and then the file you want to open. Another dialog box will ask you to enter a size in pixels and the amount of channels (choose 3 here), leave the Header Size blank and click OK.

* For the following items, always work on COPIES, not on your originals *

You might also try opening the file and re-saving it in tif format - even if you can't see anything. Save it as-is as soon as you open using the "Save As" command, then exit Photoshop and then re-open the new .tif file. You can also try rotating and saving, etc. Make sure you don't save over your original.

Last, some times the file can be opened in a text editor or a Hex editor, and the data stream altered slightly, allowing them to be opened with a graphics program. However, if there is a lot of information missing from the files, it is impossible to fully recover the images. The basic procedure is something like the following:

Open a working image files from the same source (same digital camera, etc.) as your corrupted files in a hex editor, and take a look at the flow of the files -  typically they should begin with FFD8, followed by a string of other characters. Get an idea of the flow.

Then, open your corrupt file, and look through the file. You're looking for a place where there's an obvious change to the flow of the data. If you can spot it, you might be able to fix it - at least if the damage is obvious, like a erroneous character or blank line introduced into the file.

Not to nag or say "I told you so", but ALWAYS have a backup plan and use it - recovering one lost file, like this, can pay for it.

Hope that helps,
LHerrou
0
 
LVL 27

Expert Comment

by:Jonvee
Comment Utility
wheeler2162,
There's some good advice in that last comment, and hopefully this next link will add a little more.  
Its a case where files were not accessible, and a number of helpful suggestions were made>
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/XP/Q_26404521.html
0
 
LVL 38

Expert Comment

by:BillDL
Comment Utility
Hi wheeler2162

You have an excellent comment made by LHerrou that covers a fair amount of ground.  There are a couple of parts that I would like to expand on, and add my own observations.

First off, Data Recovery applications like GetDataBack or Recuva are only going to help you if you suspect that there may be previously deleted "good" versions of the images, or if the corruption was caused by an abnormality with the hard drive's filing system that has affected areas where the affected images are stored.  They are both excellent applications for recovering deleted files or data from inaccessible hard drives, but the two applications suggested by LHerrou are much better for your needs because they concentrate on the main issues that cause image file corruption.

As mentioned by LHerrou, it is a good idea to see if other image viewing/editing applications can open the files.  There are a lot of free programs, some of which can be run as "portable" applications from a USB Flash Drive to avoid having to install them and potentially mess up file type associations.

You don't state the operating system, but the Windows Picture and Fax Viewer in XP will not load images if the "thumbnail" data in the image or the marker that tells software where to find the thumbnail is corrupt or missing.  The Picture and Fax Viewer is part of the Windows Shell, and is also used to display thumbnails and the slideshow mode when you choose "Thumbnail View" in Windows Explorer or customize a folder and tell it to use the best setting for image content.  If the unaffected image files show the thumbnails in this view and the affected ones don't, then your clue is that the thumbnail data is missing.  The Picture and fax Viewer also displays an error "Drawing Failed" immediately after you see "Generating Preview" flashing in the application window when an image's thumbnail data is missing or inaccessible.

Without the thumbnail data an image should still open in most OTHER image editing programs though.  Perhaps the user is trying to view the images ONLY in the Windows built-in viewer and the images can easily be opened and resaved to make them work again.

Have you tried copying some of the affected JPG images from the hard drive (presumably NTFS) to a FAT32-formatted USB Flash Drive and then back again?  NTFS supporting the embedding of lots of superfluous and sometimes unwanted "metadata" that can be stripped out as it is stored on a FAT32 drive.

Using a couple of COPIES of the affected images, try stripping out all the tags using David Crowell's JStrip application: http://davidcrowell.com/jstrip/
and see if the images now open in the same application that was failing to load them before.  Be aware though, that some of the "tags" that it strips out may be used by some software to eg. automatically rotate images and supply camera-specific settings to image cataloguing software.

Try opening some copies of the affected images in the following free applications:

IrfanView:  http://www.irfanview.com
XnView: http://www.xnview.com/en/xnview.html
Gimp: http://www.gimp.org
Others: http://graphicssoft.about.com/od/pixelbasedwin/tp/freephotoedw.htm

Look for the programs that offer "portable" versions for a USB Flash Drive to save clutter on your test computer.  Some of the vendors' sites offer the portable versions, while others not made as portable by the vendors have been made to work this way by others (see below).  Watch out for the misleading google ads on the download pages that are for other software.

A good way to get and run portable apps here:
http://portableapps.com/
http://portableapps.com/apps/graphics_pictures

If you get one of the above to open the affected images, then File > Save As to JPG and choose a new folder.  Some of the image editors like IrfanView and XnView support comprehensive command line support and/or GUI mode batch conversion options that would allow you to resave the affected images.

The problem you face is identifying which of the JPGs is corrupt to begin with, otherwise it could prove to be a laborious process of elimination.  JPEGSnoop by Calvin Hass is useful for this as it scans the images and produces reports:
http://www.impulseadventure.com/photo/jpeg-snoop.html
It flags errors where corruption is found.  This could be scripted into a batch file to walk through a folder and sub-folders of JPGs and identify the corrupt ones.  If you are interested in this, I'm sure I can create a batch file to do the job, or find ones I have previously used for similar purposes.


0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:wheeler2162
Comment Utility
BillDL - Still iln the process of sorting through all of this, but the prospect of having a batch file which could identify those jpgs which are corrupt would be great.  Then we would be better able to focus on opening those corrupt files rather than having to delve into each individual file.  Any help withis  would be appreciated.
0
 
LVL 38

Assisted Solution

by:BillDL
BillDL earned 125 total points
Comment Utility
Hi wheeler2162

There are a number of different forms of corruption that may have affected the JPG files.  See the orange section header entitled "Error Detection in Corrupt JPEG Photos" on this page:
http://www.impulseadventure.com/photo/jpeg-snoop-uses.html
However, if you look at the blue text at the end of that section you will see that the JPEGsnoop utility reports most detectable errors with a line starting:
"*** ERROR: "
In some cases the leading *** will not be present in the results, either in the program interface or a log file output.

For the purposes of segregating the Bad from the Good, or simply listing them, you won't need to know the exact error that was detected.  My proposal would be to run JPEGsnoop in "batch" mode, create a temporary log file for each mage scanned, and parse it for (non case-sensitive search) "ERROR".  If found, we could do any of the following:

1. Make a copy of the file in the same folder and append or prefix the new name with "bad" or "corrupt"
2. Copy affected files out to another folder entitled "Corrupt_JPGs" or similar and create a running log of file names and original folders
3. Simply create a log file in plain text for further investigation, or perhaps in CSV format to open in Excel.

Running a batch file that, for each JPG image, opens JPEGsnoop, scans the image and creates a log, then searches the log for "Error" lines, could be quite an intensive and lengthy process, especially if the JPG files are large images.  The "-nogui" switch usable with the program only tells it that you aren't using the program interface to look at the results, so it still flashes open for as long as it is scanning the image file and then closes again.

I have no way of determining how intensive or long it would be on your own customer's image repository, so it might be a good idea to test it on a single folder containing about 40 images of which at least some are thought to be corrupt.

Download JPEGsnoop from the home page:
http://www.impulseadventure.com/photo/jpeg-snoop.html
or directly from this link:
http://www.impulseadventure.com/dl.php?file=JPEGsnoop_v1_5_2.zip

Unzip it to it's own folder.  I would suggest using a folder in the C:\Drive like: C:\JpegSnoop.

The command line is quite simple, as indicated under the orange "Command Line Invocation" section header here:
http://www.impulseadventure.com/photo/jpeg-snoop-options.html

JPEGsnoop -i C:\folder\file.jpg -o c:\folder\report.txt -nogui

Save the attached batch file.  It has the .TXT extension.  Rename it, changing the extension to .CMD.  I *** DO NOT *** suggest copying and pasting the text from the Code Snippet, because I have found that it leaves trailing blanks spaces at the end of each line which can cause unexpected results.  I have included it simply for others to see if they are interested.

Place your batch file in the same folder as JPEGsnoop.exe which you unzipped after downloading it from the link above.

Right-Click > Edit the batch file to open in Notepad.  At the top you will find some   SET=  lines that declare certain variables.  This is the ONLY ONE you will need to change:

set ImgFold=C:\JPEG Files

Change my testing folder "C:\JPEG Files" to the path that reflects the master folder containing the images you want to scan with JPEGsnoop.exe.  Don't add " " around the path.  This is taken care of in the batch file.

If you, or any other scanning process, has already marked some of the files in that folder or sub-folders with a suffix matching "_corrupt" (which is probably unlikely), then change this line to some other meaningful name.

set BadSuffix=_corrupt

This is the suffix that will be appended to copies that are made of files detected by JPEGsnoop as potentially corrupt.  For example, a copy will be made in the same folder of the file named "Venice 2008.jpg" as "Venice 2008_corrupt.jpg" so that you can easily search for these files later, but so that they will still show in Windows Explorer right below the affected image file.

OK, here's what the batch file will (or should) do:

Initial checks only run once:

1. If the report named "Corrupt_JPGs.txt" already exists in the same folder as the batch file it is deleted.
2. If JPEGsnoop.exe does not exist in the same folder as the batch file it tells you and terminates.
3. If the folder set as the base folder for your images does not exist, you are told and the batch file terminates.
4. If the folder set as the base folder, or sub-folders thereof, does/do not contain any files with the *.jpg extension, you are told and the batch file terminates.
5. If the folder set as the base folder, or sub-folders thereof, contain any *.jpg files suffixed by the name set as your "BadSuffix" variable, you are warned that rescanning the folder would create additional copies of the bad images with doubled-up suffixes, you are told to change the SET= line, and the batch file terminates.

Image Processing:

1. A directory listing of *.JPG files is created for the contents of your base image folder.
2. JPEGsnoop scans each file one at a time and the following is done for each image:
2A. The temporary program log file is searched for the word "ERROR"
2B. If found, ie. the JPG scanned is detected as corrupt, a copy is made of the file in the same folder using the preset suffix, and the full path to the ORIGINAL filename is written to (appended as it goes on) to a report in the same folder as the batch file.
2C. The temporary results/log file is deleted ready for the next image scan.

So, as set in the batch file presented, your list of bad files is written to "Corrupt_JPGs.txt" as fully qualified and double-quoted paths.  The quotes can be stripped quite easily if needed.

The batch file SHOULD handle all paths and file names containing spaces.

An error check is included immediately after JPEGsnoop finishes its scan of an image to see if it exited normally (Exit Code number held in %errorlevel% variable) or abnormally (something other than a zero).  I haven't been able to get the program to fail a scan of an image, or else my exit code check is flawed, but the intention was based on the assumption that the program would fault on finding a non-supported file type with a JPG extension.  It actually scans other file types with bad extensions though, and in fact the scan report of an empty TXT file renamed as a JPG is logged as a bad file and processed in the same way as a bad JPG even though the program outputs this:
ERROR: File length is zero, no decoding done.
Oh well, that part can be removed easily enough :-)

I tried to suppress the output to the batch file from JPEGsnoop, but have not been able to do that, so I just included a "Clear Screen" (CLS) command after each loop.  A bit clunky, but the only way I could get rid of the persistent feedback being written to screen.

I have no idea whether this batch file will work on any of the "user" folders in Windows Vista or 7.  They use "junction points" and shortcuts to folders, so you never quite know if you are really in a folder or just seeing the contents of a folder elsewhere.  I have neither operating systems available, and I don't even know if JPEGsnoop runs in either of them.  I am testing in Windows XP Pro.

As I mentioned earlier, test this on a new folder containing about 40 files of which you believe some jpgs to be corrupt.

Remember, the results are dependent on what JPEGsnoop determines as being an "Error".  There may be other ways to test validity but I don't know of anything more reliable.  I mean, you could parse the text-based content of JPG files and look for missing JFIF in the header info, something like this:

for /r %%a in (*.jpg) do type "%%a" | find /i "JFIF"
if errorlevel 1 echo JFIF header not found in %%a

but that would only tell you (if it worked) that a file was not a JPG or the content was so scrambled that even that was unreadable or missing, but that's only a start.  Not really a useful check at all.

As far as repairing the images is concerned .... well, that's another story.  There are bespoke applications said to be able to repair corrupt JPG files.  I tested a few free ones a while ago.  Some didn't detect files I knew to be corrupt and others reported the correct files and displayed a partial repair or something like that, but wanted money for a licence before doing a full repair.  The methods described by Calvin Hass are limited to only certain types of corruption and involve hex-editing in portions of good sections from uncorrupted files taken by the same camera, etc, etc.  Too laborious to consider, in my opinion, unless the photos are particularly important to your customer.

 ListBadJPGs.txt

Use the download above in preference to the code below.

 
@echo off

SetLocal EnableDelayedExpansion

set CurrDir=%~dp0
set CurrDir=%CurrDir:~0,-1%

REM Note: Use CurrDir line if JPGs are in same folder as JPEGsnoop
REM set ImgFold=%CurrDir%
set ImgFold=C:\JPEG Files
set BadImgReport=%CurrDir%\Corrupt_JPGs.txt
set ProgErrLog=%CurrDir%\Failed_Scans.txt
set BadSuffix=_corrupt

if exist "%BadImgReport%" del "%BadImgReport%" > nul 2>&1

if not exist "%CurrDir%\JPEGsnoop.exe" (
    echo.
    echo   *** ERROR ***
    echo.
    echo   This batch file must be in the same folder as JPEGsnoop.exe 
    echo.
    echo   Quit the batch file and move it into the folder 
    echo   containing JPEGsnoop.exe, or vice-versa.
    echo.
    echo.
    echo   Press any key to quit ...
    pause > nul
    goto :EOF
)

if not exist "%ImgFold%" (
    echo.
    echo   *** ERROR ***
    echo.
    echo   "%ImgFold%"
    echo.
    echo   does not exist!
    echo.
    echo   Open batch file in Notepad and change the 'SET ImgFold' line
    echo   to the path containing JPGs to scan for corruption. 
    echo.
    echo.
    echo   Press any key to quit ...
    pause > nul
    goto :EOF
)

dir /on /b /s "%ImgFold%\*.jpg" | find /i ".jpg" > nul 2>&1
if errorlevel 1 (
    echo.
    echo   *** ERROR ***
    echo.
    echo   "%ImgFold%"
    echo.
    echo   and sub-folders thereof DO NOT contain any .JPG files!
    echo.
    echo   Open batch file in Notepad and change the 'SET ImgFold' line
    echo   to the path containing JPGs to scan for corruption. 
    echo.
    echo.
    echo   Press any key to quit ...
    pause > nul
    goto :EOF
)

dir /on /b /s "%ImgFold%\*_corrupt.jpg" | find /i "%BadSuffix%" > nul 2>&1
if %errorlevel% equ 0 (
    echo.
    echo   *** WARNING ***
    echo.
    echo   "%ImgFold%"
    echo.
    echo   already contains images suffixed by "_corrupt"!
    echo.
    echo   The inference is that this batch file has already been 
    echo   run on the target folder and sub-folders.
    echo.
    echo   If you were to continue, it would find the same corrupt files 
    echo   files again and append the "_corrupt" suffix in addition to
    echo   the same suffix that has already been applied to the file.
    echo.     
    echo   If you or some other program already applied the "_corrupt" 
    echo   suffix to any JPG files in the target folder or sub-folders, then
    echo   then you can open this batch file for editing and change the
    echo   'set BadSuffix' line at the top to another word, example: '_bad'.
    echo.
    echo.
    echo   Press any key to quit ...
    pause > nul
    goto :EOF
)

echo Scanning folder '%ImgFold%' and sub-folders for corrupt JPGs ...
echo.

for /f "tokens=* delims=" %%A in ('dir /on /b /s "%ImgFold%\*.jpg"') do (
    set FullPath=%%~A
    set DirPath=%%~dpA
    set JpegName=%%~nA
    set Ext=%%~xA
    call jpegsnoop.exe -nogui -i "!FullPath!" -o "%CurrDir%\!JpegName!.txt" >nul 2>&1
    if !errorlevel! NEQ 0 echo JPEGsnoop could not process "!FullPath!">>"%ProgErrLog%"
    cls
    type "%CurrDir%\!JpegName!.txt" | find /i "error"
        if !errorlevel! EQU 0 (
            echo exit code is: !errorlevel!
            copy "!FullPath!" "!DirPath!!JpegName!!BadSuffix!!Ext!"
            echo "!DirPath!!JpegName!!Ext!">>"%BadImgReport%"
        )
    if exist "%CurrDir%\!JpegName!.txt" del "%CurrDir%\!JpegName!.txt" > nul
)

REM cls
echo.
echo.
echo   ----------------------------------------------  
echo.
echo       FINISHED PROCESSING !
echo.
echo.
echo   A list of JPG files detected by JPEGsnoop to be corrupt
echo   has been written to the report :
echo.
echo   %BadImgReport%
echo.
echo   Copies of these JPG images have been created in their
echo   original folders and the word "_corrupt" has been
echo   appended to the end of their original file names.
echo.
echo.
pause

Open in new window

0
 
LVL 38

Expert Comment

by:BillDL
Comment Utility
Whoops, remove the leading   REM   from the line a few above  "Finished Processing".  I remarked it out while testing.  It's optional, and just clears the screen of the program's results of the final JPG file.
0
 
LVL 38

Expert Comment

by:BillDL
Comment Utility
Hmmm.  I forgot to use the %BadSuffix% variable later in my error messages.  I have attached a revised version that is otherwise the same and corrects the statement made in the comment above.  Sorry for the multiple posts.

 ListBadJPGs-Fixed.txt
0
 
LVL 69

Expert Comment

by:Merete
Comment Utility
Could you post one of the corrupted photos here so I can run some tests in my photo editing tools
0
 
LVL 38

Expert Comment

by:younghv
Comment Utility
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

PaperPort (http://www.nuance.com/for-individuals/by-product/paperport/index.htm) is among the most important applications that I run on my Windows computers. I use it every day, for nearly all of my document and photo scanning, as well as most of my…
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Microsoft Office Picture Manager is not included in Office 2013. This comes as quite a surprise to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This video expla…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now