Lightroom: "unexpected end-of-file" (win)

  • 2
  • Problem
  • Updated 6 years ago
  • (Edited)
I get an " unexpected end-of-file" with Lightroom 4!
What should I do in order to get rid of it???
I have not changed anything on the PC!
Windows7 and Lightroom 4
Photo of Erik Ranstad

Erik Ranstad

  • 2 Posts
  • 0 Reply Likes

Posted 6 years ago

  • 2
Photo of Erik Ranstad

Erik Ranstad

  • 2 Posts
  • 0 Reply Likes
I was running a check on my harddisks and they are supposed to be OK!
These files have been OK previously!
Photo of jdv

jdv, Champion

  • 728 Posts
  • 56 Reply Likes
When, exactly, do you get this message? Sounds like bad media.
Photo of stefan ziegler

stefan ziegler

  • 7 Posts
  • 1 Reply Like
I had this issue all of a sudden, too. I tried various tips on the internet but all in vain.

Luckily, I had one file that was damaged but also had an undamaged version of the same. After analyzing the hex code of the two files and comparing bit by bit, it became apparent that the damaged file was actually truncated by just the last byte (8 bits or 2 hexadecimal signs).

This happened to files from various cameras including .nef (Nikon) and .arw (Sony). It seems that the program knows the length of each file, tries to read to the very end and then notices that something is missing.

The solution that worked for all my damaged files goes as follows:

1. download freeware Hexplorer (a hexadecimal editor). This can be found on http://sourceforge.net/projects/hexpl...

2. Open one of the damaged files - have it displayed as hexadecimal code. Scroll to the very bottom of the entire file. At the very end of the file, append '1A'. It actually does not matter what you append - it is probably the last pixel of your picture that is missing and confusing Lightroom. As long as you add two valid hexadecimal numbers (the missing byte), it will be fine.

3. that's it. Reopen the same file in Lightroom and it should work. I managed to recover all my 93 damaged files with no problem.

Further remarks:
a) I did not investigate details of the various raw formats of the manufactures. Thus, I am assuming that the last remaining byte is just a pixel - however, I am not sure about this.
My procedure certainly did not change any of the metadata or the picture itself. However, the procedure manged to recover the files.
b) a faster way to fix files is to use the lightroom command 'show file in explorer', then open this file (by setting temporarily hexplorer as the default program to open .nef or .arw files) and then edit the file in hexplorer.
c) I identified all my broken files by running an export across the entire collection of fotos (approximately 50'000 which took a few days...). The files that failed to export were consistently those that were broken.
d) I not only had issues opening the file in Lightroom but also in photoshop and various other programs.

Hope this helps. Ziggy61
Photo of Heikki Salokanto

Heikki Salokanto

  • 3 Posts
  • 0 Reply Likes
My best guess is that Adobe's NEF reader algorithm is just less tolerant for errors. CaptureNX and Dxo Optics Pro (to name a few) can still process the files despite the mismatch of the real file size and the size specified in the NEF header, which means that they more or less disregard the latter.

I'm almost certain that the files are indeed corrupt, due to a faulty memory card or camera hardware (or firmware). I personally tried with different computers and card readers and even an older Lightroom (3.6), tried to import directly from within LR or copy the files to the HDD manually, and none of that made any difference.
Photo of stefan ziegler

stefan ziegler

  • 7 Posts
  • 1 Reply Like
I am almost certain that the problem is caused by Lightroom.
I have tons of photos but I rarely edit or use them with anything other than Lightroom. However, I sort, tag, keyword them and copy them to various folders on the server.
The files definitely were intact when being copied onto my server. I was able to recuperate older version of some pictures (as originally copied on the server) and they all were fine. Also, the files were from different cameras and memory cards, too. So I can exclude issues with memory cards or servers.
Thus, my best assumption is that it is a LR problem. I was going through almost every version of LR from 2.0 to 4.2 now and from gutfeeling would believe that these issues were happening with verision 3.x but I can't be totally certain about this. I did not have this symptom lately, however.
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 379 Reply Likes
Well, I really don't know. - except, problems whose symptoms have the tell-tale sign of hardware corruption (blocks and strips due to stuck bits...), usually are due to hardware problems (99.999% of the time...). But, files that are short by a byte or 10k are more likely to be due to software. But, such a problem would only happen if Lightroom was re-writing the file, which normally it doesn't do. Or if some other software re-wrote the file(s) - could that be possible? e.g. was the file copied? capture time updated? if not, I've still got my money on a hardware problem, despite how it may seem.
Photo of Heikki Salokanto

Heikki Salokanto

  • 3 Posts
  • 0 Reply Likes
Whether LR modifies a file is quite easily ruled out by removing write permissions from the file (or setting it as read-only in some other way)
Photo of stefan ziegler

stefan ziegler

  • 7 Posts
  • 1 Reply Like
I tend to agree with Rob. As the files were once intact, copied from the memory card to the server (still intact) and worked on (still intact) but all of a sudden - after shifting from one folder to another not intact anymore, it would seem that something happened within LR. The thing is that all had the same symptom (missing the last bit), came from different cameras and were moved from one folder to another by LR. Even if it was read only, LR would still move the file - essentially copying and deleting (e.g. from temporary storage on the computer to longterm storage on the NAS).
Photo of Heikki Salokanto

Heikki Salokanto

  • 3 Posts
  • 0 Reply Likes
Thank you Ziggy61 for the research.

I was suffering from the same problem, with the exception that simply appending one byte didn't fix it. 10 kB, however, did.

If you have Cygwin installed or access to a Linux system, you can apply the 10k-append to all the photos in the current directory with:

$ for i in *.NEF; do perl -e 'print chr(0) for (1..10000)' >>$i; done

...or if you don't have perl:

$ for i in *.NEF; do dd if=/dev/zero bs=10k count=1 of=$i oflag=append conv=notrunc; done

Appending 10k of null doesn't seem to break anything, thus non-corrupted files can be treated with that, too.