CVE-2017-8358 (published 2017-04-30T17:59Z)

LibreOffice before 2017-03-17 has an out-of-bounds write caused by a heap-based buffer overflow related to the ReadJPEG function in vcl/source/filter/jpeg/jpegc.cxx.

Severity: HIGH
CVSS v2 base score: 7.5 (AV:N/AC:L/Au:N/C:P/I:P/A:P)
CVSS v3 base score: 9.8, CRITICAL (CVSS:3.0/AV:N/AC:L/PR:N/UI:N/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.
         
         
cwe_id: CWE-787
cwe_name: Out-of-bounds Write
description: The product writes data past the end, or before the beginning, of the intended buffer.
extended_description: 
            
            
             
			 
         
         

Fix information:
repo_url: https://github.com/LibreOffice/core
commit_details: repo_url: https://github.com/LibreOffice/core
author: Caolán McNamara
author_date: 2017-03-17 10:57:03+00:00
msg: ofz#889 readjust jpeg import

Change-Id: I4e25db429b8dee9265ab2ad468c21cc34a50df6c
Reviewed-on: https://gerrit.libreoffice.org/35325
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
repository: repo_url: https://github.com/LibreOffice/core
repo_name: LibreOffice/core
description: Read-only LibreOffice core repo - no pull request (use gerrit instead https://gerrit.libreoffice.org/) - don't download zip, use https://dev-www.libreoffice.org/bundles/  instead
repo_language: C++
owner: LibreOffice
file_changes: filename: jpegc.cxx
change_type: ModificationType.MODIFY
diff: @@ -132,7 +132,7 @@ void ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines,
         }
     }
 
-    jpeg_start_decompress( &cinfo );
+    jpeg_calc_output_dimensions(&cinfo);
 
     long nWidth = cinfo.output_width;
     long nHeight = cinfo.output_height;
@@ -161,7 +161,6 @@ void ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines,
             J_COLOR_SPACE best_out_color_space = JCS_RGB;
             ScanlineFormat eScanlineFormat = ScanlineFormat::N24BitTcRgb;
             ScanlineFormat eFinalFormat = pAccess->GetScanlineFormat();
-
             if (eFinalFormat == ScanlineFormat::N32BitTcBgra)
             {
                 best_out_color_space = JCS_EXT_BGRA;
@@ -190,10 +189,12 @@ void ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines,
                 cinfo.out_color_space != JCS_GRAYSCALE &&
                 cinfo.out_color_space != best_out_color_space)
             {
-                SAL_WARN("vcl.filter", "jpg with unknown out color space, forcing to :" << best_out_color_space);
+                SAL_WARN("vcl.filter", "jpg with unknown out color space, forcing to :" << best_out_color_space << " gray ");
                 cinfo.out_color_space = best_out_color_space;
             }
 
+            jpeg_start_decompress(&cinfo);
+
             JSAMPLE* aRangeLimit = cinfo.sample_range_limit;
 
             std::vector<sal_uInt8> pScanLineBuffer(nWidth * (bGray ? 1 : nPixelSize));

programming_language: C++