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

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