Author: post
Date: 2009-12-19 15:32:35 +0100 (Sat, 19 Dec 2009)
New Revision: 175
Added:
RawSpeed/IOException.cpp
RawSpeed/IOException.h
Modified:
RawSpeed/ArwDecoder.cpp
RawSpeed/BitPumpJPEG.h
RawSpeed/ByteStream.h
RawSpeed/DngDecoder.cpp
RawSpeed/FileIOException.h
RawSpeed/FileMap.cpp
RawSpeed/FileMap.h
RawSpeed/NefDecoder.cpp
RawSpeed/RawDecoder.cpp
RawSpeed/RawSpeed.cpp
RawSpeed/RawSpeed.vcproj
RawSpeed/Rw2Decoder.cpp
RawSpeed/rawstudio-plugin.makefile
Log:
Added truncated file tests.
Fixed various issues with truncated files.
Modified: RawSpeed/ArwDecoder.cpp
===================================================================
--- RawSpeed/ArwDecoder.cpp 2009-12-19 11:29:00 UTC (rev 174)
+++ RawSpeed/ArwDecoder.cpp 2009-12-19 14:32:35 UTC (rev 175)
@@ -90,16 +90,25 @@
guint c2 = counts->getInt();
guint off = offsets->getInt();
+
+ if (!mFile->isValid(off))
+ ThrowRDE("Sony ARW decoder: Data offset after EOF, file probably
truncated");
+
if (!mFile->isValid(off + c2))
c2 = mFile->getSize() - off;
+
ByteStream input(mFile->getData(off), c2);
+
+ try {
+ if (arw1)
+ DecodeARW(input, width, height);
+ else
+ DecodeARW2(input, width, height, bitPerPixel);
+ } catch (IOException e) {
+ // Let's ignore it, it may have delivered somewhat useful data.
+ }
- if (arw1)
- DecodeARW(input, width, height);
- else
- DecodeARW2(input, width, height, bitPerPixel);
-
return mRaw;
}
Modified: RawSpeed/BitPumpJPEG.h
===================================================================
--- RawSpeed/BitPumpJPEG.h 2009-12-19 11:29:00 UTC (rev 174)
+++ RawSpeed/BitPumpJPEG.h 2009-12-19 14:32:35 UTC (rev 175)
@@ -21,6 +21,7 @@
*/
#pragma once
#include "ByteStream.h"
+#include "IOException.h"
namespace RawSpeed {
Modified: RawSpeed/ByteStream.h
===================================================================
--- RawSpeed/ByteStream.h 2009-12-19 11:29:00 UTC (rev 174)
+++ RawSpeed/ByteStream.h 2009-12-19 14:32:35 UTC (rev 175)
@@ -20,6 +20,7 @@
http://www.klauspost.com
*/
#pragma once
+#include "IOException.h"
namespace RawSpeed {
@@ -46,12 +47,4 @@
};
-class IOException : public std::runtime_error
-{
-public:
- IOException(const string _msg) : runtime_error(_msg) {
- _RPT1(0, "IO Exception: %s\n", _msg.c_str());
- }
-};
-
} // namespace RawSpeed
Modified: RawSpeed/DngDecoder.cpp
===================================================================
--- RawSpeed/DngDecoder.cpp 2009-12-19 11:29:00 UTC (rev 174)
+++ RawSpeed/DngDecoder.cpp 2009-12-19 14:32:35 UTC (rev 175)
@@ -257,6 +257,9 @@
}
}
guint nSlices = slices.size();
+ if (!nSlices)
+ ThrowRDE("DNG Decoder: No valid slices found.");
+
slices.startDecoding();
if (!slices.errors.empty())
Modified: RawSpeed/FileIOException.h
===================================================================
--- RawSpeed/FileIOException.h 2009-12-19 11:29:00 UTC (rev 174)
+++ RawSpeed/FileIOException.h 2009-12-19 14:32:35 UTC (rev 175)
@@ -25,7 +25,7 @@
namespace RawSpeed {
-void ThrowTPE(const char* fmt, ...);
+void ThrowFIE(const char* fmt, ...);
class FileIOException: public RawDecoderException
{
Modified: RawSpeed/FileMap.cpp
===================================================================
--- RawSpeed/FileMap.cpp 2009-12-19 11:29:00 UTC (rev 174)
+++ RawSpeed/FileMap.cpp 2009-12-19 14:32:35 UTC (rev 175)
@@ -51,6 +51,13 @@
return new_map;
}
+FileMap* FileMap::cloneRandomSize() {
+ guint new_size = (rand() | (rand() << 15)) % size;
+ FileMap *new_map = new FileMap(new_size);
+ memcpy(new_map->data, data, new_size);
+ return new_map;
+}
+
void FileMap::corrupt(int errors) {
for (int i = 0; i < errors; i++) {
guint pos = (rand() | (rand() << 15)) % size;
@@ -58,4 +65,10 @@
}
}
+const guchar* FileMap::getData( guint offset )
+{
+ if (offset >= size)
+ throw IOException("FileMap: Attempting to read out of file.");
+ return &data[offset];
+}
} // namespace RawSpeed
Modified: RawSpeed/FileMap.h
===================================================================
--- RawSpeed/FileMap.h 2009-12-19 11:29:00 UTC (rev 174)
+++ RawSpeed/FileMap.h 2009-12-19 14:32:35 UTC (rev 175)
@@ -22,6 +22,8 @@
http://www.klauspost.com
*/
+#include "IOException.h"
+
namespace RawSpeed {
/*************************************************************************
@@ -38,12 +40,14 @@
FileMap(guint _size); // Allocates the data array itself
FileMap(guchar* _data, guint _size); // Data already allocated.
~FileMap(void);
- const guchar* getData(guint offset) {return &data[offset];}
+ const guchar* getData(guint offset);
guchar* getDataWrt(guint offset) {return &data[offset];}
guint getSize() {return size;}
gboolean isValid(guint offset) {return offset<=size;}
FileMap* clone();
+ /* For testing purposes */
void corrupt(int errors);
+ FileMap* cloneRandomSize();
private:
guchar* data;
guint size;
Added: RawSpeed/IOException.cpp
===================================================================
--- RawSpeed/IOException.cpp (rev 0)
+++ RawSpeed/IOException.cpp 2009-12-19 14:32:35 UTC (rev 175)
@@ -0,0 +1,52 @@
+#include "StdAfx.h"
+#include "IOException.h"
+#ifndef WIN32
+#include <stdarg.h>
+#define vsprintf_s(...) vsnprintf(__VA_ARGS__)
+#endif
+
+/*
+ RawSpeed - RAW file decoder.
+
+ Copyright (C) 2009 Klaus Post
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
+
+ http://www.klauspost.com
+*/
+
+namespace RawSpeed {
+
+void ThrowIOE(const char* fmt, ...) {
+ va_list val;
+ va_start(val, fmt);
+ char buf[8192];
+ vsprintf_s(buf, 8192, fmt, val);
+ va_end(val);
+ _RPT1(0, "IO EXCEPTION: %s\n", buf);
+ throw IOException(buf);
+}
+
+
+IOException::IOException( const char* _msg ) : std::runtime_error(string(_msg))
+{
+ _RPT1(0, "IO Exception: %s\n", _msg);
+}
+
+IOException::IOException( const string _msg ) : std::runtime_error(_msg)
+{
+ _RPT1(0, "IO Exception: %s\n", _msg.c_str());
+}
+} // namespace RawSpeed
Added: RawSpeed/IOException.h
===================================================================
--- RawSpeed/IOException.h (rev 0)
+++ RawSpeed/IOException.h 2009-12-19 14:32:35 UTC (rev 175)
@@ -0,0 +1,35 @@
+#include "RawDecoderException.h"
+
+/*
+ RawSpeed - RAW file decoder.
+
+ Copyright (C) 2009 Klaus Post
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
+
+ http://www.klauspost.com
+*/
+#pragma once
+
+namespace RawSpeed {
+
+class IOException : public std::runtime_error
+{
+public:
+ IOException(const char* _msg);
+ IOException(const string _msg);
+};
+
+} // namespace RawSpeed
Modified: RawSpeed/NefDecoder.cpp
===================================================================
--- RawSpeed/NefDecoder.cpp 2009-12-19 11:29:00 UTC (rev 174)
+++ RawSpeed/NefDecoder.cpp 2009-12-19 14:32:35 UTC (rev 175)
@@ -159,6 +159,9 @@
slices.push_back(slice);
}
+ if (0 == slices.size())
+ ThrowRDE("NEF Decoder: No valid slices found. File probably truncated.");
+
mRaw->dim = iPoint2D(width, offY);
mRaw->bpp = 2;
mRaw->createData();
Modified: RawSpeed/RawDecoder.cpp
===================================================================
--- RawSpeed/RawDecoder.cpp 2009-12-19 11:29:00 UTC (rev 174)
+++ RawSpeed/RawDecoder.cpp 2009-12-19 14:32:35 UTC (rev 175)
@@ -176,7 +176,10 @@
me->parent->decodeThreaded(me);
} catch (RawDecoderException ex) {
me->error = _strdup(ex.what());
+ } catch (IOException ex) {
+ me->error = _strdup(ex.what());
}
+
pthread_exit(NULL);
return 0;
}
Modified: RawSpeed/RawSpeed.cpp
===================================================================
--- RawSpeed/RawSpeed.cpp 2009-12-19 11:29:00 UTC (rev 174)
+++ RawSpeed/RawSpeed.cpp 2009-12-19 14:32:35 UTC (rev 175)
@@ -38,7 +38,7 @@
int startTime;
// Open file, or test corrupt file
-#if 1
+#if 0
// Open file and save as tiff
void OpenFile(FileReader f, CameraMetaData *meta) {
RawDecoder *d = 0;
@@ -125,7 +125,12 @@
RawDecoder *d = 0;
FileMap* m = 0;
wprintf(L"Opening:%s\n",f.Filename());
- m = f.readFile();
+ try {
+ m = f.readFile();
+ } catch (FileIOException e) {
+ printf("Could not open image:%s\n", e.what());
+ return;
+ }
srand(0xC0CAC01A); // Hardcoded seed for re-producability (on the same
platform)
int tests = 50;
@@ -147,7 +152,7 @@
guint time = GetTickCount()-startTime;
float mpps = (float)r->dim.x * (float)r->dim.y * (float)r->getCpp() /
(1000.0f * (float)time);
- wprintf(L"(%d/%d) Decoding %s took: %u ms, %4.2f Mpixel/s\n", i+1,
tests, f.Filename(), time, mpps);
+ wprintf(L"(%d/%d) Decoding %s took: %u ms, %4.2f Mpixel/s\n", i+1,
tests*2, f.Filename(), time, mpps);
for (guint i = 0; i < d->errors.size(); i++) {
printf("Error Encountered:%s\n", d->errors[i]);
}
@@ -160,11 +165,47 @@
MultiByteToWideChar(CP_ACP, 0, e.what(), -1, uni, 1024);
wprintf(L"Tiff Parser Exception:%s\n",uni);
}
- delete m2;
- if (d)
- delete d;
- d = 0;
+ delete m2;
+ if (d)
+ delete d;
+ d = 0;
}
+ srand(0xC0CAC01A); // Hardcoded seed for re-producability (on the same
platform)
+ wprintf(L"Performing truncation tests\n");
+ for (int i = 0 ; i < tests; i++) {
+ // Get truncated file
+ FileMap *m2 = m->cloneRandomSize();
+ try {
+ TiffParser t(m2);
+ t.parseData();
+ d = t.getDecoder();
+
+ startTime = GetTickCount();
+
+ d->decodeRaw();
+ d->decodeMetaData(meta);
+ RawImage r = d->mRaw;
+
+ guint time = GetTickCount()-startTime;
+ float mpps = (float)r->dim.x * (float)r->dim.y * (float)r->getCpp() /
(1000.0f * (float)time);
+ wprintf(L"(%d/%d) Decoding %s took: %u ms, %4.2f Mpixel/s\n", i+1+tests,
tests*2, f.Filename(), time, mpps);
+ for (guint i = 0; i < d->errors.size(); i++) {
+ printf("Error Encountered:%s\n", d->errors[i]);
+ }
+ } catch (RawDecoderException e) {
+ wchar_t uni[1024];
+ MultiByteToWideChar(CP_ACP, 0, e.what(), -1, uni, 1024);
+ wprintf(L"Raw Decoder Exception:%s\n",uni);
+ } catch (TiffParserException e) {
+ wchar_t uni[1024];
+ MultiByteToWideChar(CP_ACP, 0, e.what(), -1, uni, 1024);
+ wprintf(L"Tiff Parser Exception:%s\n",uni);
+ }
+ delete m2;
+ if (d)
+ delete d;
+ d = 0;
+ }
}
#endif
@@ -181,7 +222,7 @@
#endif
CameraMetaData meta("..\\cameras.xml");
//meta.dumpXML();
-
+/*
OpenFile(FileReader(L"..\\testimg\\Panasonic_FZ35FARI0200.RW2"),&meta);
OpenFile(FileReader(L"..\\testimg\\Panasonic_FZ35hSLI0200.RW2"),&meta);
OpenFile(FileReader(L"..\\testimg\\Panasonic_FZ35hVFAWB.RW2"),&meta);
@@ -250,7 +291,30 @@
OpenFile(FileReader(L"..\\testimg\\Canon_EOS_1Ds_Mk3.cr2"),&meta);
OpenFile(FileReader(L"..\\testimg\\Canon_EOS_400D.cr2"),&meta);
-
+ OpenFile(FileReader(L"..\\testimg\\500D_NR-Std_ISO1600.CR2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\canon_eos_1000d_01.cr2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\canon_eos_1000d_06.cr2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Canon_EOS_1D_Mk2_N.cr2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Canon_EOS_30D-uga1.cr2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Canon_EOS_350D-3.cr2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Canon_EOS_450D-4.cr2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Canon_EOS_50D.cr2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Canon_EOS_7DhMULTII00200.CR2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Canon_EOS_Mk2-ISO100_sRAW2.CR2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Canon_Powershot_G9-1.CR2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Nikon-D3000hMULTII0200.NEF"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Nikon-D3000hSLI0200.NEF"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Nikon-D3x_ISO100.NEF"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Olympus-E620_NF-Std_ISO100.ORF"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\Olympus-E-620-1.ORF"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\panasonic_DMC-G1hMULTII0200.RW2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\panasonic_DMC-G1hSLI0400.RW2"),&meta);
+
OpenFile(FileReader(L"..\\testimg\\panasonic_lumix_dmc_g1_04_portrait.rw2"),&meta);
+
OpenFile(FileReader(L"..\\testimg\\panasonic_lumix_dmc_gh1_02_portrait.rw2"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\sony_a330_02.arw"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\sony_a330_04.arw"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\sony_a330_05.arw"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\sony_a330_06.arw"),&meta);
OpenFile(FileReader(L"..\\testimg\\Pentax_K10D-2.dng"),&meta);
OpenFile(FileReader(L"..\\testimg\\Pentax_K10D.pef"),&meta);
@@ -279,7 +343,7 @@
OpenFile(FileReader(L"..\\testimg\\Sony_A900_ISO400_uncompressed.ARW"),&meta);
OpenFile(FileReader(L"..\\testimg\\Sony_A900_ISO6400_uncompressed.ARW"),&meta);
OpenFile(FileReader(L"..\\testimg\\Sony_A900_ISO800_uncompressed.ARW"),&meta);
- OpenFile(FileReader(L"..\\testimg\\nikon_coolpix_p6000_05.nrw"),&meta);
+ OpenFile(FileReader(L"..\\testimg\\nikon_coolpix_p6000_05.nrw"),&meta);*/
OpenFile(FileReader(L"..\\testimg\\Nikon_D1.nef"),&meta);
OpenFile(FileReader(L"..\\testimg\\Nikon_D100-backhigh.nef"),&meta);
OpenFile(FileReader(L"..\\testimg\\Nikon_D200_compressed-1.nef"),&meta);
@@ -310,7 +374,6 @@
OpenFile(FileReader(L"..\\testimg\\pentax_kx_10.pef"),&meta);
OpenFile(FileReader(L"..\\testimg\\pentax_kx_12.pef"),&meta);
-
OpenFile(FileReader(L"..\\testimg\\Canon_Powershot_SX1IShMULTII1600.CR2"),&meta);
OpenFile(FileReader(L"..\\testimg\\Canon_Powershot_SX1ISFARI0200.CR2"),&meta);
OpenFile(FileReader(L"..\\testimg\\Canon_Powershot_SX1IShMULTII0200.CR2"),&meta);
Modified: RawSpeed/RawSpeed.vcproj
===================================================================
--- RawSpeed/RawSpeed.vcproj 2009-12-19 11:29:00 UTC (rev 174)
+++ RawSpeed/RawSpeed.vcproj 2009-12-19 14:32:35 UTC (rev 175)
@@ -189,10 +189,6 @@
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
- RelativePath=".\FileIOException.cpp"
- >
- </File>
- <File
RelativePath=".\RawImage.cpp"
>
</File>
@@ -340,6 +336,10 @@
>
</File>
<File
+ RelativePath=".\FileIOException.cpp"
+ >
+ </File>
+ <File
RelativePath=".\FileMap.cpp"
>
</File>
@@ -347,6 +347,10 @@
RelativePath=".\FileReader.cpp"
>
</File>
+ <File
+ RelativePath=".\IOException.cpp"
+ >
+ </File>
</Filter>
<Filter
Name="Decoders"
@@ -462,6 +466,10 @@
>
</File>
<File
+ RelativePath=".\IOException.h"
+ >
+ </File>
+ <File
RelativePath=".\Point.h"
>
</File>
Modified: RawSpeed/Rw2Decoder.cpp
===================================================================
--- RawSpeed/Rw2Decoder.cpp 2009-12-19 11:29:00 UTC (rev 174)
+++ RawSpeed/Rw2Decoder.cpp 2009-12-19 14:32:35 UTC (rev 175)
@@ -59,14 +59,11 @@
load_flags = 0x2008;
gint off = offsets->getInt();
- input_start = new ByteStream(mFile->getData(off), mFile->getSize() - off);
- try {
- DecodeRw2();
- } catch (IOException e) {
- // We attempt to ignore, since truncated files may be ok.
- errors.push_back(e.what());
- }
+ if (!mFile->isValid(off))
+ ThrowRDE("RW2 Decoder: Invalid image data offset, cannot decode.");
+ input_start = new ByteStream(mFile->getData(off), mFile->getSize() - off);
+ DecodeRw2();
return mRaw;
}
Modified: RawSpeed/rawstudio-plugin.makefile
===================================================================
--- RawSpeed/rawstudio-plugin.makefile 2009-12-19 11:29:00 UTC (rev 174)
+++ RawSpeed/rawstudio-plugin.makefile 2009-12-19 14:32:35 UTC (rev 175)
@@ -21,6 +21,7 @@
FileIOException.cpp \
FileMap.cpp \
FileReader.cpp \
+ IOException.cpp \
LJpegDecompressor.cpp \
LJpegPlain.cpp \
NefDecoder.cpp \
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit