2cf66c
diff -urNp old/dcraw.c new/dcraw.c
2cf66c
--- old/dcraw.c	2018-06-14 12:38:10.519964843 +0200
2cf66c
+++ new/dcraw.c	2018-06-14 13:31:46.304679761 +0200
2cf66c
@@ -1248,6 +1248,10 @@ void CLASS nikon_load_raw()
2cf66c
 
2cf66c
 void CLASS nikon_yuv_load_raw()
2cf66c
 {
2cf66c
+#ifdef LIBRAW_LIBRARY_BUILD
2cf66c
+  if(!image)
2cf66c
+    throw LIBRAW_EXCEPTION_IO_CORRUPT;
2cf66c
+#endif
2cf66c
   int row, col, yuv[4], rgb[3], b, c;
2cf66c
   UINT64 bitbuf=0;
2cf66c
 
2cf66c
@@ -1889,6 +1893,10 @@ void CLASS sinar_4shot_load_raw()
2cf66c
     unpacked_load_raw();
2cf66c
     return;
2cf66c
   }
2cf66c
+#ifdef LIBRAW_LIBRARY_BUILD
2cf66c
+  else if(!image)
2cf66c
+    throw LIBRAW_EXCEPTION_IO_CORRUPT;
2cf66c
+#endif
2cf66c
   pixel = (ushort *) calloc (raw_width, sizeof *pixel);
2cf66c
   merror (pixel, "sinar_4shot_load_raw()");
2cf66c
   for (shot=0; shot < 4; shot++) {
2cf66c
@@ -2188,6 +2196,11 @@ void CLASS quicktake_100_load_raw()
2cf66c
 
2cf66c
 void CLASS kodak_radc_load_raw()
2cf66c
 {
2cf66c
+#ifdef LIBRAW_LIBRARY_BUILD
2cf66c
+  // All kodak radc images are 768x512
2cf66c
+  if(width>768 || raw_width>768 || height > 512 || raw_height>512 )
2cf66c
+    throw LIBRAW_EXCEPTION_IO_CORRUPT;
2cf66c
+#endif
2cf66c
   static const char src[] = {
2cf66c
     1,1, 2,3, 3,4, 4,2, 5,7, 6,5, 7,6, 7,8,
2cf66c
     1,0, 2,1, 3,3, 4,4, 5,2, 6,7, 7,6, 8,5, 8,8,
2cf66c
@@ -2348,6 +2361,10 @@ void CLASS gamma_curve (double pwr, doub
2cf66c
 
2cf66c
 void CLASS lossy_dng_load_raw()
2cf66c
 {
2cf66c
+#ifdef LIBRAW_LIBRARY_BUILD
2cf66c
+  if(!image)
2cf66c
+    throw LIBRAW_EXCEPTION_IO_CORRUPT;
2cf66c
+#endif
2cf66c
   struct jpeg_decompress_struct cinfo;
2cf66c
   struct jpeg_error_mgr jerr;
2cf66c
   JSAMPARRAY buf;
2cf66c
@@ -2444,6 +2461,10 @@ void CLASS eight_bit_load_raw()
2cf66c
 
2cf66c
 void CLASS kodak_c330_load_raw()
2cf66c
 {
2cf66c
+#ifdef LIBRAW_LIBRARY_BUILD
2cf66c
+  if(!image)
2cf66c
+    throw LIBRAW_EXCEPTION_IO_CORRUPT;
2cf66c
+#endif
2cf66c
   uchar *pixel;
2cf66c
   int row, col, y, cb, cr, rgb[3], c;
2cf66c
 
2cf66c
@@ -2469,6 +2490,10 @@ void CLASS kodak_c330_load_raw()
2cf66c
 
2cf66c
 void CLASS kodak_c603_load_raw()
2cf66c
 {
2cf66c
+#ifdef LIBRAW_LIBRARY_BUILD
2cf66c
+  if(!image)
2cf66c
+    throw LIBRAW_EXCEPTION_IO_CORRUPT;
2cf66c
+#endif
2cf66c
   uchar *pixel;
2cf66c
   int row, col, y, cb, cr, rgb[3], c;
2cf66c
 
2cf66c
@@ -2596,6 +2621,10 @@ void CLASS kodak_65000_load_raw()
2cf66c
 
2cf66c
 void CLASS kodak_ycbcr_load_raw()
2cf66c
 {
2cf66c
+#ifdef LIBRAW_LIBRARY_BUILD
2cf66c
+  if(!image)
2cf66c
+    throw LIBRAW_EXCEPTION_IO_CORRUPT;
2cf66c
+#endif
2cf66c
   short buf[384], *bp;
2cf66c
   int row, col, len, c, i, j, k, y[2][2], cb, cr, rgb[3];
2cf66c
   ushort *ip;
2cf66c
@@ -2624,6 +2653,10 @@ void CLASS kodak_ycbcr_load_raw()
2cf66c
 
2cf66c
 void CLASS kodak_rgb_load_raw()
2cf66c
 {
2cf66c
+#ifdef LIBRAW_LIBRARY_BUILD
2cf66c
+  if(!image)
2cf66c
+    throw LIBRAW_EXCEPTION_IO_CORRUPT;
2cf66c
+#endif
2cf66c
   short buf[768], *bp;
2cf66c
   int row, col, len, c, i, rgb[3];
2cf66c
   ushort *ip=image[0];
2cf66c
@@ -2640,6 +2673,10 @@ void CLASS kodak_rgb_load_raw()
2cf66c
 
2cf66c
 void CLASS kodak_thumb_load_raw()
2cf66c
 {
2cf66c
+#ifdef LIBRAW_LIBRARY_BUILD
2cf66c
+  if(!image)
2cf66c
+    throw LIBRAW_EXCEPTION_IO_CORRUPT;
2cf66c
+#endif
2cf66c
   int row, col;
2cf66c
   colors = thumb_misc >> 5;
2cf66c
   for (row=0; row < height; row++)
2cf66c
@@ -3109,6 +3146,10 @@ void CLASS foveon_thumb()
2cf66c
 
2cf66c
 void CLASS foveon_sd_load_raw()
2cf66c
 {
2cf66c
+#ifdef LIBRAW_LIBRARY_BUILD
2cf66c
+  if(!image)
2cf66c
+    throw LIBRAW_EXCEPTION_IO_CORRUPT;
2cf66c
+#endif
2cf66c
   struct decode *dindex;
2cf66c
   short diff[1024];
2cf66c
   unsigned bitbuf=0;
2cf66c
@@ -3156,6 +3197,10 @@ void CLASS foveon_huff (ushort *huff)
2cf66c
 
2cf66c
 void CLASS foveon_dp_load_raw()
2cf66c
 {
2cf66c
+#ifdef LIBRAW_LIBRARY_BUILD
2cf66c
+  if(!image)
2cf66c
+    throw LIBRAW_EXCEPTION_IO_CORRUPT;
2cf66c
+#endif
2cf66c
   unsigned c, roff[4], row, col, diff;
2cf66c
   ushort huff[512], vpred[2][2], hpred[2];
2cf66c