Bug 1036980 (CVE-2017-8345)

Summary: VUL-1: CVE-2017-8345: ImageMagick, GraphicsMagick: denial of service (memory leak) via a crafted file (ReadMNGImage func in png.c)
Product: [Novell Products] SUSE Security Incidents Reporter: Mikhail Kasimov <mikhail.kasimov>
Component: IncidentsAssignee: Security Team bot <security-team>
Status: RESOLVED FIXED QA Contact: Security Team bot <security-team>
Severity: Normal    
Priority: P3 - Medium CC: jsegitz, pgajdos
Version: unspecified   
Target Milestone: unspecified   
Hardware: Other   
OS: Other   
Whiteboard: CVSSv2:NVD:CVE-2017-8345:4.3:(AV:N/AC:M/Au:N/C:N/I:N/A:P) CVSSv2:SUSE:CVE-2017-8345:4.3:(AV:N/AC:M/Au:N/C:N/I:N/A:P) CVSSv3:NVD:CVE-2017-8345:6.5:(AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H)
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: CVE-2017-8345_memory-leak-in-ReadMNGImage-4_testcase

Description Mikhail Kasimov 2017-04-30 20:02:11 UTC
Created attachment 723253 [details]
CVE-2017-8345_memory-leak-in-ReadMNGImage-4_testcase

Ref: https://nvd.nist.gov/vuln/detail/CVE-2017-8345
===================================================
Description

In ImageMagick 7.0.5-5, the ReadMNGImage function in png.c allows attackers to cause a denial of service (memory leak) via a crafted file.

Source:  MITRE      Last Modified:  04/30/2017
===================================================

Hyperlink

[1] https://github.com/ImageMagick/ImageMagick/issues/442

[2] Testcase: https://github.com/bestshow/p0cs/blob/master/memory-leak-in-ReadMNGImage-4.mng

[3] https://github.com/ImageMagick/ImageMagick/commit/7dea03d2f10279c065dad4be2591f4b160660636 (master)

[4] https://github.com/ImageMagick/ImageMagick/commit/fd6144f89f33f3065b0a8436f9af81ab9561459f (ImageMagick-6)


(open-)SUSE: https://software.opensuse.org/package/ImageMagick

7.0.5.4 (TW, official repo)
6.8.8.1 (42.{1,2}, official repo)
Comment 1 Petr Gajdos 2017-05-02 14:26:51 UTC
(In reply to Mikhail Kasimov from comment #0)
> [3]
> https://github.com/ImageMagick/ImageMagick/commit/
> 7dea03d2f10279c065dad4be2591f4b160660636 (master)
> 
> [4]
> https://github.com/ImageMagick/ImageMagick/commit/
> fd6144f89f33f3065b0a8436f9af81ab9561459f (ImageMagick-6)

There seem to be much more related in png.c history. I guess kind of minimal patch would be good.
Comment 2 Petr Gajdos 2017-05-03 09:40:23 UTC
For the testcase from comment 0:

(gdb) run
Breakpoint 4, ReadMNGImage (image_info=0x61cb30, exception=0x605410) at coders/png.c:5064
5064	        ThrowReaderException(CorruptImageError,"ImproperImageHeader");
(gdb) l
5059	        magic_number[MaxTextExtent];
5060	
5061	      /* Verify MNG signature.  */
5062	      count=(size_t) ReadBlob(image,8,(unsigned char *) magic_number);
5063	      if (memcmp(magic_number,"\212MNG\r\n\032\n",8) != 0)
5064	        ThrowReaderException(CorruptImageError,"ImproperImageHeader");
5065	
5066	      /* Initialize some nonzero members of the MngInfo structure.  */
5067	      for (i=0; i < MNG_MAX_OBJECTS; i++)
5068	      {
(gdb) 

For maintenance, instead of refactoring the code, maybe we could inspire myself in GraphicsMagick's changesets:

http://hg.code.sf.net/p/graphicsmagick/code/log/b416eff9eca7/coders/png.c

(search for 'leak')

For example this one:
http://hg.code.sf.net/p/graphicsmagick/code/diff/bd4fa5efd278/coders/png.c

should fix the leak for testcase from comment 0.
Comment 3 Petr Gajdos 2017-05-05 09:57:00 UTC
Affected: 12/ImageMagick, 11/GraphicsMagick, 11/ImageMagick, 42.1/GraphicsMagick and marginally also 42.2/GraphicsMagick

12/ImageMagick: took the refactorization
others: took commits from GraphicsMagick Mercurial repo referenced in comment 2
Comment 4 Petr Gajdos 2017-05-17 15:12:53 UTC
I believe all fixed.
Comment 9 Swamp Workflow Management 2017-06-06 16:12:23 UTC
SUSE-SU-2017:1489-1: An update that fixes 27 vulnerabilities is now available.

Category: security (moderate)
Bug References: 1028075,1033091,1034870,1034872,1034876,1036976,1036977,1036978,1036980,1036981,1036982,1036983,1036984,1036985,1036986,1036987,1036988,1036989,1036990,1036991,1037527,1038000,1040025,1040303,1040304,1040306,1040332
CVE References: CVE-2017-6502,CVE-2017-7606,CVE-2017-7941,CVE-2017-7942,CVE-2017-7943,CVE-2017-8343,CVE-2017-8344,CVE-2017-8345,CVE-2017-8346,CVE-2017-8347,CVE-2017-8348,CVE-2017-8349,CVE-2017-8350,CVE-2017-8351,CVE-2017-8352,CVE-2017-8353,CVE-2017-8354,CVE-2017-8355,CVE-2017-8356,CVE-2017-8357,CVE-2017-8765,CVE-2017-8830,CVE-2017-9098,CVE-2017-9141,CVE-2017-9142,CVE-2017-9143,CVE-2017-9144
Sources used:
SUSE Linux Enterprise Workstation Extension 12-SP2 (src):    ImageMagick-6.8.8.1-70.1
SUSE Linux Enterprise Software Development Kit 12-SP2 (src):    ImageMagick-6.8.8.1-70.1
SUSE Linux Enterprise Server for Raspberry Pi 12-SP2 (src):    ImageMagick-6.8.8.1-70.1
SUSE Linux Enterprise Server 12-SP2 (src):    ImageMagick-6.8.8.1-70.1
SUSE Linux Enterprise Desktop 12-SP2 (src):    ImageMagick-6.8.8.1-70.1
Comment 11 Swamp Workflow Management 2017-06-14 13:12:07 UTC
openSUSE-SU-2017:1560-1: An update that fixes 27 vulnerabilities is now available.

Category: security (moderate)
Bug References: 1028075,1033091,1034870,1034872,1034876,1036976,1036977,1036978,1036980,1036981,1036982,1036983,1036984,1036985,1036986,1036987,1036988,1036989,1036990,1036991,1037527,1038000,1040025,1040303,1040304,1040306,1040332
CVE References: CVE-2017-6502,CVE-2017-7606,CVE-2017-7941,CVE-2017-7942,CVE-2017-7943,CVE-2017-8343,CVE-2017-8344,CVE-2017-8345,CVE-2017-8346,CVE-2017-8347,CVE-2017-8348,CVE-2017-8349,CVE-2017-8350,CVE-2017-8351,CVE-2017-8352,CVE-2017-8353,CVE-2017-8354,CVE-2017-8355,CVE-2017-8356,CVE-2017-8357,CVE-2017-8765,CVE-2017-8830,CVE-2017-9098,CVE-2017-9141,CVE-2017-9142,CVE-2017-9143,CVE-2017-9144
Sources used:
openSUSE Leap 42.2 (src):    ImageMagick-6.8.8.1-30.3.1
Comment 12 Swamp Workflow Management 2017-06-19 10:11:22 UTC
SUSE-SU-2017:1599-1: An update that fixes 25 vulnerabilities is now available.

Category: security (moderate)
Bug References: 1033091,1034870,1034872,1034876,1036976,1036978,1036980,1036981,1036983,1036984,1036985,1036986,1036987,1036988,1036989,1036990,1037527,1038000,1040025,1040303,1040304,1040306,1040332
CVE References: CVE-2014-9846,CVE-2016-10050,CVE-2017-7606,CVE-2017-7941,CVE-2017-7942,CVE-2017-7943,CVE-2017-8344,CVE-2017-8345,CVE-2017-8346,CVE-2017-8348,CVE-2017-8349,CVE-2017-8350,CVE-2017-8351,CVE-2017-8352,CVE-2017-8353,CVE-2017-8354,CVE-2017-8355,CVE-2017-8357,CVE-2017-8765,CVE-2017-8830,CVE-2017-9098,CVE-2017-9141,CVE-2017-9142,CVE-2017-9143,CVE-2017-9144
Sources used:
SUSE Linux Enterprise Software Development Kit 11-SP4 (src):    ImageMagick-6.4.3.6-7.77.1
SUSE Linux Enterprise Server 11-SP4 (src):    ImageMagick-6.4.3.6-7.77.1
SUSE Linux Enterprise Debuginfo 11-SP4 (src):    ImageMagick-6.4.3.6-7.77.1
Comment 13 Swamp Workflow Management 2017-06-19 13:10:49 UTC
SUSE-SU-2017:1600-1: An update that fixes 17 vulnerabilities is now available.

Category: security (moderate)
Bug References: 1033091,1034876,1036978,1036980,1036981,1036984,1036985,1036986,1036987,1036988,1036990,1037527,1038000,1040025,1040304,1040332,984144
CVE References: CVE-2014-9847,CVE-2017-7606,CVE-2017-7941,CVE-2017-8344,CVE-2017-8345,CVE-2017-8346,CVE-2017-8349,CVE-2017-8350,CVE-2017-8351,CVE-2017-8352,CVE-2017-8353,CVE-2017-8355,CVE-2017-8765,CVE-2017-8830,CVE-2017-9098,CVE-2017-9142,CVE-2017-9144
Sources used:
SUSE Studio Onsite 1.3 (src):    GraphicsMagick-1.2.5-4.77.1
SUSE Linux Enterprise Software Development Kit 11-SP4 (src):    GraphicsMagick-1.2.5-4.77.1
SUSE Linux Enterprise Debuginfo 11-SP4 (src):    GraphicsMagick-1.2.5-4.77.1
Comment 14 Marcus Meissner 2017-06-20 07:27:53 UTC
released