CVE-2017-16909 (published 2018-12-07T22:29Z)

An error related to the "LibRaw::panasonic_load_raw()" function (dcraw_common.cpp) in LibRaw versions prior to 0.18.6 can be exploited to cause a heap-based buffer overflow and subsequently cause a crash via a specially crafted TIFF image.

Severity: MEDIUM
CVSS v2 base score: 6.8 (AV:N/AC:M/Au:N/C:P/I:P/A:P)
CVSS v3 base score: 8.8, HIGH (CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-119
cwe_name: Improper Restriction of Operations within the Bounds of a Memory Buffer
description: The product performs operations on a memory buffer, but it reads from or writes to a memory location outside the buffer's intended boundary. This may result in read or write operations on unexpected memory locations that could be linked to other variables, data structures, or internal program data.
extended_description: 
            Certain languages allow direct addressing of memory locations and do not automatically ensure that these locations are valid for the memory buffer that is being referenced. This can cause read or write operations to be performed on memory locations that may be associated with other variables, data structures, or internal program data.
         
         

Fix information:
repo_url: https://github.com/LibRaw/LibRaw
commit_details: repo_url: https://github.com/LibRaw/LibRaw
author: Alex Tutubalin
author_date: 2017-12-02 12:01:40+03:00
msg: SECUNIA advisory 76000 #1 (wrong fuji width set via tiff tag
repository: repo_url: https://github.com/LibRaw/LibRaw
repo_name: LibRaw/LibRaw
description: LibRaw is a library for reading RAW files from digital cameras
repo_language: C++
owner: LibRaw
file_changes: filename: dcraw.c
change_type: ModificationType.MODIFY
diff: @@ -3172,7 +3172,7 @@ void CLASS panasonic_load_raw()
   int row, col, i, j, sh = 0, pred[2], nonz[2];
 
   pana_bits(0);
-  for (row = 0; row < height; row++)
+  for (row = 0; row < raw_height; row++)
   {
 #ifdef LIBRAW_LIBRARY_BUILD
     checkCancel();
@@ -3194,7 +3194,7 @@ void CLASS panasonic_load_raw()
       }
       else if ((nonz[i & 1] = pana_bits(8)) || i > 11)
         pred[i & 1] = nonz[i & 1] << 4 | pana_bits(4);
-      if ((RAW(row, col) = pred[col & 1]) > 4098 && col < width)
+      if ((RAW(row, col) = pred[col & 1]) > 4098 && col < width && row < height)
         derror();
     }
   }
@@ -15037,6 +15037,9 @@ void CLASS parse_fuji(int offset)
   entries = get4();
   if (entries > 255)
     return;
+#ifdef LIBRAW_LIBRARY_BUILD
+  imgdata.process_warnings |=  LIBRAW_WARN_PARSEFUJI_PROCESSED; 
+#endif
   while (entries--)
   {
     tag = get2();
@@ -19580,6 +19583,11 @@ dng_skip:
     if (raw_color)
       adobe_coeff("Apple", "Quicktake");
 
+#ifdef LIBRAW_LIBRARY_BUILD
+  // Clear erorneus fuji_width if not set through parse_fuji or for DNG
+  if(fuji_width && !dng_version && !(imgdata.process_warnings & LIBRAW_WARN_PARSEFUJI_PROCESSED ))
+     fuji_width = 0;
+#endif
   if (fuji_width)
   {
     fuji_width = width >> !fuji_layout;

programming_language: C++
filename: dcraw_common.cpp
change_type: ModificationType.MODIFY
diff: @@ -2875,7 +2875,7 @@ void CLASS panasonic_load_raw()
   int row, col, i, j, sh = 0, pred[2], nonz[2];
 
   pana_bits(0);
-  for (row = 0; row < height; row++)
+  for (row = 0; row < raw_height; row++)
   {
 #ifdef LIBRAW_LIBRARY_BUILD
     checkCancel();
@@ -2897,7 +2897,7 @@ void CLASS panasonic_load_raw()
       }
       else if ((nonz[i & 1] = pana_bits(8)) || i > 11)
         pred[i & 1] = nonz[i & 1] << 4 | pana_bits(4);
-      if ((RAW(row, col) = pred[col & 1]) > 4098 && col < width)
+      if ((RAW(row, col) = pred[col & 1]) > 4098 && col < width && row < height)
         derror();
     }
   }
@@ -13708,6 +13708,9 @@ void CLASS parse_fuji(int offset)
   entries = get4();
   if (entries > 255)
     return;
+#ifdef LIBRAW_LIBRARY_BUILD
+  imgdata.process_warnings |=  LIBRAW_WARN_PARSEFUJI_PROCESSED; 
+#endif
   while (entries--)
   {
     tag = get2();
@@ -18091,6 +18094,11 @@ dng_skip:
     if (raw_color)
       adobe_coeff("Apple", "Quicktake");
 
+#ifdef LIBRAW_LIBRARY_BUILD
+  // Clear erorneus fuji_width if not set through parse_fuji or for DNG
+  if(fuji_width && !dng_version && !(imgdata.process_warnings & LIBRAW_WARN_PARSEFUJI_PROCESSED ))
+     fuji_width = 0;
+#endif
   if (fuji_width)
   {
     fuji_width = width >> !fuji_layout;

programming_language: C++
filename: libraw_const.h
change_type: ModificationType.MODIFY
diff: @@ -231,7 +231,8 @@ enum LibRaw_warnings
   LIBRAW_WARN_RAWSPEED_PROBLEM = 1 << 12,
   LIBRAW_WARN_RAWSPEED_UNSUPPORTED = 1 << 13,
   LIBRAW_WARN_RAWSPEED_PROCESSED = 1 << 14,
-  LIBRAW_WARN_FALLBACK_TO_AHD = 1 << 15
+  LIBRAW_WARN_FALLBACK_TO_AHD = 1 << 15,
+  LIBRAW_WARN_PARSEFUJI_PROCESSED = 1 << 16
 };
 
 enum LibRaw_exceptions

programming_language: C++