Blame SOURCES/advancecomp-1.15-CVE-2019-8379.patch

9eece9
commit 7894a6e684ce68ddff9f4f4919ab8e3911ac8040
9eece9
Author: Andrea Mazzoleni <amadvance@gmail.com>
9eece9
Date:   Fri Jan 4 20:49:48 2019 +0100
9eece9
9eece9
    Fix a buffer overflow caused by invalid chunks
9eece9
9eece9
diff --git a/pngex.cc b/pngex.cc
9eece9
index 55d16f5..3f5b49f 100644
9eece9
--- a/pngex.cc
9eece9
+++ b/pngex.cc
9eece9
@@ -163,6 +163,10 @@ void png_print_chunk(unsigned type, unsigned char* data, unsigned size)
9eece9
 
9eece9
 	switch (type) {
9eece9
 		case ADV_MNG_CN_MHDR :
9eece9
+			if (size < 28) {
9eece9
+				cout << " invalid chunk size";
9eece9
+				break;
9eece9
+			}
9eece9
 			cout << " width:" << be_uint32_read(data+0) << " height:" << be_uint32_read(data+4) << " frequency:" << be_uint32_read(data+8);
9eece9
 			cout << " simplicity:" << be_uint32_read(data+24);
9eece9
 			cout << "(bit";
9eece9
@@ -174,6 +178,10 @@ void png_print_chunk(unsigned type, unsigned char* data, unsigned size)
9eece9
 			cout << ")";
9eece9
 		break;
9eece9
 		case ADV_MNG_CN_DHDR :
9eece9
+			if (size < 4) {
9eece9
+				cout << " invalid chunk size";
9eece9
+				break;
9eece9
+			}
9eece9
 			cout << " id:" << be_uint16_read(data+0);
9eece9
 			switch (data[2]) {
9eece9
 				case 0 : cout << " img:unspecified"; break;
9eece9
@@ -243,6 +251,10 @@ void png_print_chunk(unsigned type, unsigned char* data, unsigned size)
9eece9
 			}
9eece9
 			break;
9eece9
 		case ADV_MNG_CN_DEFI :
9eece9
+			if (size < 2) {
9eece9
+				cout << " invalid chunk size";
9eece9
+				break;
9eece9
+			}
9eece9
 			cout << " id:" << be_uint16_read(data+0);
9eece9
 			if (size >= 3) {
9eece9
 				switch (data[2]) {
9eece9
@@ -266,6 +278,10 @@ void png_print_chunk(unsigned type, unsigned char* data, unsigned size)
9eece9
 			}
9eece9
 		break;
9eece9
 		case ADV_MNG_CN_MOVE :
9eece9
+			if (size < 13) {
9eece9
+				cout << " invalid chunk size";
9eece9
+				break;
9eece9
+			}
9eece9
 			cout << " id_from:" << be_uint16_read(data+0) << " id_to:" << be_uint16_read(data+2);
9eece9
 			switch (data[4]) {
9eece9
 				case 0 : cout << " type:replace"; break;
9eece9
@@ -275,6 +291,10 @@ void png_print_chunk(unsigned type, unsigned char* data, unsigned size)
9eece9
 			cout << " x:" << (int)be_uint32_read(data + 5) << " y:" << (int)be_uint32_read(data + 9);
9eece9
 			break;
9eece9
 		case ADV_MNG_CN_PPLT :
9eece9
+			if (size < 1) {
9eece9
+				cout << " invalid chunk size";
9eece9
+				break;
9eece9
+			}
9eece9
 			switch (data[0]) {
9eece9
 				case 0 : cout << " type:replacement_rgb"; break;
9eece9
 				case 1 : cout << " type:delta_rgb"; break;
9eece9
@@ -285,7 +305,7 @@ void png_print_chunk(unsigned type, unsigned char* data, unsigned size)
9eece9
 				default : cout << " type:?"; break;
9eece9
 			}
9eece9
 			i = 1;
9eece9
-			while (i
9eece9
+			while (i + 1 < size) {
9eece9
 				unsigned ssize;
9eece9
 				cout << " " << (unsigned)data[i] << ":" << (unsigned)data[i+1];
9eece9
 				if (data[0] == 0 || data[1] == 1)
9eece9
@@ -298,6 +318,10 @@ void png_print_chunk(unsigned type, unsigned char* data, unsigned size)
9eece9
 			}
9eece9
 			break;
9eece9
 		case ADV_PNG_CN_IHDR :
9eece9
+			if (size < 13) {
9eece9
+				cout << " invalid chunk size";
9eece9
+				break;
9eece9
+			}
9eece9
 			cout << " width:" << be_uint32_read(data) << " height:" << be_uint32_read(data + 4);
9eece9
 			cout << " depth:" << (unsigned)data[8];
9eece9
 			cout << " color_type:" << (unsigned)data[9];