Author: post
Date: 2009-12-20 22:28:39 +0100 (Sun, 20 Dec 2009)
New Revision: 180

Modified:
   RawSpeed/DngDecoder.cpp
   RawSpeed/NefDecoder.cpp
   RawSpeed/RawDecoder.cpp
Log:
Fix various crashes on random/truncated input. 

Modified: RawSpeed/DngDecoder.cpp
===================================================================
--- RawSpeed/DngDecoder.cpp     2009-12-20 18:22:23 UTC (rev 179)
+++ RawSpeed/DngDecoder.cpp     2009-12-20 21:28:39 UTC (rev 180)
@@ -192,8 +192,11 @@
           // DNG spec says that if not 8 or 16 bit/sample, always use big 
endian
           if (bps != 8 && bps != 16)
             big_endian = true;
-
-          readUncompressedRaw(in, size, pos, width*bps / 8, bps, big_endian);
+          try {
+            readUncompressedRaw(in, size, pos, width*bps / 8, bps, big_endian);
+          } catch(IOException ex) {
+            // Let's ignore this, we may have some valid data.
+          }
         }
 
       } catch (TiffParserException) {
@@ -212,6 +215,9 @@
         if (raw->hasEntry(TILEOFFSETS)) {
           guint tilew = raw->getEntry(TILEWIDTH)->getInt();
           guint tileh = raw->getEntry(TILELENGTH)->getInt();
+          if (!tilew || !tileh)
+            ThrowRDE("DNG Decoder: Invalid tile size");
+
           guint tilesX = (mRaw->dim.x + tilew - 1) / tilew;
           guint tilesY = (mRaw->dim.y + tileh - 1) / tileh;
           guint nTiles = tilesX * tilesY;
@@ -329,6 +335,7 @@
     }
   }
   mRaw->whitePoint = raw->getEntry(WHITELEVEL)->getInt();
+  new_size = mRaw->dim;
 
   int black = -1; // Estimate, if no blacklevel
   if (raw->hasEntry(BLACKLEVELREPEATDIM)) {

Modified: RawSpeed/NefDecoder.cpp
===================================================================
--- RawSpeed/NefDecoder.cpp     2009-12-20 18:22:23 UTC (rev 179)
+++ RawSpeed/NefDecoder.cpp     2009-12-20 21:28:39 UTC (rev 180)
@@ -50,6 +50,8 @@
   TiffEntry *counts = raw->getEntry(STRIPBYTECOUNTS);
 
   if (!data[0]->getEntry(MODEL)->getString().compare("NIKON D100 ")) {  
/**Sigh**/
+    if (!mFile->isValid(offsets->getInt()))
+      ThrowRDE("NEF Decoder: Image data outside of file.");
     if (!D100IsCompressed(offsets->getInt())) {
       DecodeD100Uncompressed();
       return mRaw;

Modified: RawSpeed/RawDecoder.cpp
===================================================================
--- RawSpeed/RawDecoder.cpp     2009-12-20 18:22:23 UTC (rev 179)
+++ RawSpeed/RawDecoder.cpp     2009-12-20 21:28:39 UTC (rev 180)
@@ -62,6 +62,7 @@
     w *= cpp;
     for (; y < h; y++) {
       gushort* dest = (gushort*) & 
data[offset.x*sizeof(gushort)*cpp+y*outPitch];
+      bits.checkPos();
       for (guint x = 0 ; x < w; x++) {
         guint b = bits.getBits(bitPerPixel);
         dest[x] = b;
@@ -80,6 +81,7 @@
     w *= cpp;
     for (; y < h; y++) {
       gushort* dest = (gushort*) & data[offset.x*sizeof(gushort)+y*outPitch];
+      bits.checkPos();
       for (guint x = 0 ; x < w; x++) {
         guint b = bits.getBits(bitPerPixel);
         dest[x] = b;


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to