Project

General

Profile

Exeption "Failed to read image data"

Added by Anonymous over 8 years ago

Hi!

I tried to read EXIF data from attached file. But when I call method readMetadata(), I get exception: "Failed to read image data" although method get() doesn't return 0. This exception happens only on Windows application, on Linux it work fine. Also, if you tried execute command print for this file using "Exiv2 v0.23 Windows executable" you will get the same exception.

When I open this image using another program, for example, FastStone I can see EXIF data for this file.

Can you, please, describe how can I read EXIF data from this file, or how to check if EXIF date is bad not using catching exception (because I have problem with catcing exeption on Windows). What method can I call to check file?
Or maybe this is bug in Exiv2?

Thanks, for attention.


Replies (12)

RE: Exeption "Failed to read image data" - Added by Nehal J Wani over 8 years ago

Hey!
You said that "This exception happens only on Windows application, on Linux it work fine." But I am using Linux and getting the same error. Perhaps the image file is corrupt. Could you please check and re-attach the file? Or are you talking of this corrupted file only?

When I open the image in any browser, I get the error:
The image "http://dev.exiv2.org/attachments/459/0_71669_fa7746c8_orig.jpg" cannot be displayed because it contains errors.

RE: Exeption "Failed to read image data" - Added by Anonymous over 8 years ago

I rechecked this image (I mean corrupted file) on Linux. You are right it causes exception on Linux too.
So, I am interesting, is there any way to check this kind of file before it cause exception (because I have problem to catch exception on Windows).

I also have tried to open this image in all viewers I have, but only FastStone shown EXIF data for this image.

RE: Exeption "Failed to read image data" - Added by Nehal J Wani over 8 years ago

It is not the case that only FastStone shows EXIF data for this image. I ran exif on this image in Linux and got output (http://pastebin.com/LmuP7ji7). Other exif tools say "This photo does NOT contain EXIF metadata". There might be a parsing bug in exiv2 (I won't call it a real bug, as the file is corrupt, but still). Most probably, it is jpgimage.cpp which throws error code 14.

In most image files, the meta-data is defined in the first 100k of the file. So one can check the file size before performing any further action. In this case, the file was 1.1k in size, which seems arbitrarily truncated and hence corrupted.

I'll discuss exception handling in terminal. In Linux, one can catch exception by noting the return code of the exiv2 program. If it is non-zero (In this case 1), then one can be sure that some error has been raised.

In the example below, L.jpg is perfect while 0_71669_fa7746c8_orig.jpg is corrupt.

[Wani@Linux exiv2-0.23]$ exiv2 ~/Temp/L.jpg > Output; echo $?
0
[Wani@Linux exiv2-0.23]$ exiv2 ~/0_71669_fa7746c8_orig.jpg > Output; echo $?
Exiv2 exception in print action for file /home/Wani/0_71669_fa7746c8_orig.jpg:
Failed to read image data
1
[Wani@Linux exiv2-0.23]$

If you are using say, a C/C++ program and calling exiv2 via system(), then the return value of the call will give the exit code.
To see how to record the same in Windows, read http://goo.gl/ekb8d

RE: Exeption "Failed to read image data" - Added by Anonymous over 8 years ago

I used exiv2 as a library in my Qt-based app. So, this exception cause crash in my app, when I want app still working, may be without showing EXIF data.

So I need way to check file with this kind of corruption by calling some check method.
Now, method Exiv2::Image::AutoPtr::get() doesn't return 0 for this file. Is there any other way to check file before exception will happens?

RE: Exeption "Failed to read image data" - Added by Robin Mills over 8 years ago

Two suggestions:

1) Can you catch it with try { .... } catch ( ... ) { ... }; in your C++ code ?
2) If that doesn't work, you could execute a small sample application such as exifprint with system() and test the return code as described by Nehal. If exifprint crashed, there's no point in opening with library linked to your application. That will isolate your Qt process and avoid the crash.

Robin

RE: Exeption "Failed to read image data" - Added by Anonymous over 8 years ago

1) I can't catch exception, because 'catch' doesn't called in Windows.
2) I develop image viewer app. So, this way, I think, is not so quick, because I can call methods for getting exif data for hundreds image in the same time. For, example, for getting preview for all RAW-image in folder.

Thanks, for help. I think it it makes sense to open issue for this 'bug'.

RE: Exeption "Failed to read image data" - Added by Robin Mills over 8 years ago

A couple of questions:

1) Which compiler/build system are you using on Windows?
QtCreator/Visual Studio? Which compiler GCC, Clang, CL, something else?

2) Do you know paths to hundreds of images before you open them?
You don't need to open them one at a time. I wrote a script (which I've put below) and exiv2 opened a file 200 times in 1.2 seconds on my rather elderly Windows/XP machine:

592 rmills@nv10042:~/gnu/exiv2/test.build/samples $ foo.sh
26
real    0m1.219s
user    0m0.546s
sys     0m0.358s
5200 foo.txt
593 rmills@nv10042:~/gnu/exiv2/test.build/samples $

Here's the script:

#!/bin/sh
exiv2 ~/R.jpg | wc -l
time exiv2 \
~/R.jpg ~/R.jpg ~/R.jpg ~/R.jpg ~/R.jpg ~/R.jpg ~/R.jpg ~/R.jpg ~/R.jpg ~/R.jpg \
... repeated ...
~/R.jpg ~/R.jpg ~/R.jpg ~/R.jpg ~/R.jpg ~/R.jpg ~/R.jpg ~/R.jpg ~/R.jpg ~/R.jpg \
> foo.txt
wc -l  foo.txt

I'll take a look at your file this evening after work.

RE: Exeption "Failed to read image data" - Added by Anonymous over 8 years ago

I had built library in Linux using:

./configure --prefix=/usr/i586-mingw32msvc
make

and use obtained dll for linking app in Windows.

I am going to try build Exiv2 library in Windows this weekend. Maybe it will helps me with catching exceptions.

RE: Exeption "Failed to read image data" - Added by Robin Mills over 8 years ago

And are you building your app with QtCreator on Windows?

RE: Exeption "Failed to read image data" - Added by Robin Mills over 8 years ago

Aleksandr

I'm puzzled. I've run exiv2(.exe) on several platforms and with your file, they are report:

Exiv2 exception in print action for file Aleks.jpg:
Failed to read image data

This message is being generated from actions.cpp where there is an exception handler.
int Print::run(const std::string& path)
    try {
        path_ = path;
        int rc = 0;
        switch (Params::instance().printMode_) {
        case Params::pmSummary: rc = printSummary();     break;
        case Params::pmList:    rc = printList();        break;
        case Params::pmComment: rc = printComment();     break;
        case Params::pmPreview: rc = printPreviewList(); break;
        }
        return rc;
    }
    catch(const Exiv2::AnyError& e) {
        std::cerr << "Exiv2 exception in print action for file " 
                  << path << ":\n" << e << "\n";
        return 1;
    } // Print::run
This isn't a bug. The library throws an exception and it's the caller's responsibility to catch it - as illustrated in the code above.

You've said "I can't catch exception, because 'catch' doesn't called in Windows.". For sure, the catch is working on Windows on the Cygwin and MSVC builds.

I seldom use MinGW and the version of QtCreator I have installed on my Windows machine is for building with Visual Studio. It's going to take a considerable effort to download and install Qt/QtCreator/MinGW/GCC/CMake and whatever else is needed to build everything with MinGW/Qt/QtCreator.

Can you build please build exiv2(.exe) and/or samples/exifprint(.exe) on your platform and use them on your file from the command-line. Did exiv2 really manage to exit without printing "Exiv2 exception in print action....." ? Can you share the output from the program?

RE: Exeption "Failed to read image data" - Added by Anonymous over 8 years ago

I had built Exiv2 library on Windows using this help: http://dev.exiv2.org/boards/3/topics/1259 (this help is really useful)
and now I can catch exception!!!

Thank to all for the help!

RE: Exeption "Failed to read image data" - Added by fdsf hfgh about 8 years ago

library is a way to read image data, you can also install an image windows viewer c#http://www.rasteredge.com/how-to/csharp-imaging/create-windows-viewer/. there are many on the web, google around, you can find one similar to faststone. it also display multiple image formats.

    (1-12/12)