Blame SOURCES/dcraw-9.19-CVE-2013-1438.patch

c1da72
From 24f099951c3a86f04a29adc7b0dda474a3c44722 Mon Sep 17 00:00:00 2001
c1da72
From: Nils Philippsen <nils@redhat.com>
c1da72
Date: Wed, 25 Sep 2013 15:04:43 +0200
c1da72
Subject: [PATCH] CVE-2013-1438: fix various security issues
c1da72
c1da72
This fixes division by zero, infinite loop, and null pointer dereference
c1da72
bugs. Ported from Alex Tutubalin's fix in LibRaw (commit
c1da72
9ae25d8c3a6bfb40c582538193264f74c9b93bc0).
c1da72
---
c1da72
 dcraw.c | 33 ++++++++++++++++++++++++---------
c1da72
 1 file changed, 24 insertions(+), 9 deletions(-)
c1da72
c1da72
diff --git a/dcraw.c b/dcraw.c
c1da72
index 96e3d1f..dcf284c 100644
c1da72
--- a/dcraw.c
c1da72
+++ b/dcraw.c
c1da72
@@ -828,6 +828,9 @@ int CLASS ljpeg_diff (ushort *huff)
c1da72
 {
c1da72
   int len, diff;
c1da72
 
c1da72
+  if (!huff)
c1da72
+    longjmp(failure, 2);
c1da72
+
c1da72
   len = gethuff(huff);
c1da72
   if (len == 16 && (!dng_version || dng_version >= 0x1010000))
c1da72
     return -32768;
c1da72
@@ -883,6 +886,8 @@ void CLASS lossless_jpeg_load_raw()
c1da72
   ushort *rp;
c1da72
 
c1da72
   if (!ljpeg_start (&jh, 0)) return;
c1da72
+  if (jh.wide < 1 || jh.high < 1 || jh.clrs < 1 || jh.bits < 1)
c1da72
+    longjmp (failure, 2);
c1da72
   jwide = jh.wide * jh.clrs;
c1da72
 
c1da72
   for (jrow=0; jrow < jh.high; jrow++) {
c1da72
@@ -902,6 +907,8 @@ void CLASS lossless_jpeg_load_raw()
c1da72
       }
c1da72
       if (raw_width == 3984 && (col -= 2) < 0)
c1da72
 	col += (row--,raw_width);
c1da72
+      if (row > raw_height)
c1da72
+        longjmp (failure, 3);
c1da72
       if ((unsigned) row < raw_height) RAW(row,col) = val;
c1da72
       if (++col >= raw_width)
c1da72
 	col = (row++,0);
c1da72
@@ -5444,6 +5451,7 @@ int CLASS parse_tiff_ifd (int base)
c1da72
 	  data_offset = get4()+base;
c1da72
 	  ifd++;  break;
c1da72
 	}
c1da72
+  if(len > 1000) len=1000; /* 1000 SubIFDs is enough */
c1da72
 	while (len--) {
c1da72
 	  i = ftell(ifp);
c1da72
 	  fseek (ifp, get4()+base, SEEK_SET);
c1da72
@@ -5662,7 +5670,7 @@ guess_cfa_pc:
c1da72
 	break;
c1da72
       case 50715:			/* BlackLevelDeltaH */
c1da72
       case 50716:			/* BlackLevelDeltaV */
c1da72
-	for (num=i=0; i < len; i++)
c1da72
+	for (num=i=0; i < len && i < 65536; i++)
c1da72
 	  num += getreal(type);
c1da72
 	black += num/len + 0.5;
c1da72
 	break;
c1da72
@@ -5787,9 +5795,13 @@ void CLASS apply_tiff()
c1da72
   if (thumb_offset) {
c1da72
     fseek (ifp, thumb_offset, SEEK_SET);
c1da72
     if (ljpeg_start (&jh, 1)) {
c1da72
-      thumb_misc   = jh.bits;
c1da72
-      thumb_width  = jh.wide;
c1da72
-      thumb_height = jh.high;
c1da72
+      if ((unsigned)jh.bits < 17 && (unsigned)jh.wide < 0x10000 &&
c1da72
+          (unsigned)jh.high < 0x10000)
c1da72
+        {
c1da72
+          thumb_misc   = jh.bits;
c1da72
+          thumb_width  = jh.wide;
c1da72
+          thumb_height = jh.high;
c1da72
+        }
c1da72
     }
c1da72
   }
c1da72
   for (i=0; i < tiff_nifds; i++) {
c1da72
@@ -5797,8 +5809,9 @@ void CLASS apply_tiff()
c1da72
 	max_samp = tiff_ifd[i].samples;
c1da72
     if (max_samp > 3) max_samp = 3;
c1da72
     if ((tiff_ifd[i].comp != 6 || tiff_ifd[i].samples != 3) &&
c1da72
-	(tiff_ifd[i].width | tiff_ifd[i].height) < 0x10000 &&
c1da72
-	tiff_ifd[i].width*tiff_ifd[i].height > raw_width*raw_height) {
c1da72
+	      (tiff_ifd[i].width | tiff_ifd[i].height) < 0x10000 &&
c1da72
+        (unsigned)tiff_ifd[i].bps < 33 && (unsigned)tiff_ifd[i].samples < 13 &&
c1da72
+        tiff_ifd[i].width*tiff_ifd[i].height > raw_width*raw_height) {
c1da72
       raw_width     = tiff_ifd[i].width;
c1da72
       raw_height    = tiff_ifd[i].height;
c1da72
       tiff_bps      = tiff_ifd[i].bps;
c1da72
@@ -5884,9 +5897,11 @@ void CLASS apply_tiff()
c1da72
       is_raw = 0;
c1da72
   for (i=0; i < tiff_nifds; i++)
c1da72
     if (i != raw && tiff_ifd[i].samples == max_samp &&
c1da72
-	tiff_ifd[i].width * tiff_ifd[i].height / (SQR(tiff_ifd[i].bps)+1) >
c1da72
-	      thumb_width *       thumb_height / (SQR(thumb_misc)+1)
c1da72
-	&& tiff_ifd[i].comp != 34892) {
c1da72
+        tiff_ifd[i].bps > 0 && tiff_ifd[i].bps < 33 &&
c1da72
+        ((unsigned)(tiff_ifd[i].width | tiff_ifd[i].height)) < 0x10000 &&
c1da72
+        tiff_ifd[i].width * tiff_ifd[i].height / (SQR(tiff_ifd[i].bps)+1) >
c1da72
+              thumb_width *       thumb_height / (SQR(thumb_misc)+1)
c1da72
+        && tiff_ifd[i].comp != 34892) {
c1da72
       thumb_width  = tiff_ifd[i].width;
c1da72
       thumb_height = tiff_ifd[i].height;
c1da72
       thumb_offset = tiff_ifd[i].offset;
c1da72
-- 
c1da72
1.8.4.2
c1da72