1ebb4b
--- libwmf-0.2.8.4/src/ipa/ipa/bmp.h	2015-06-08 14:46:24.591876404 +0100
1ebb4b
+++ libwmf-0.2.8.4/src/ipa/ipa/bmp.h	2015-06-08 14:46:35.345993247 +0100
1ebb4b
@@ -859,7 +859,7 @@
1ebb4b
 %
1ebb4b
 %
1ebb4b
 */
1ebb4b
-static void DecodeImage (wmfAPI* API,wmfBMP* bmp,BMPSource* src,unsigned int compression,unsigned char* pixels)
1ebb4b
+static int DecodeImage (wmfAPI* API,wmfBMP* bmp,BMPSource* src,unsigned int compression,unsigned char* pixels)
1ebb4b
 {	int byte;
1ebb4b
 	int count;
1ebb4b
 	int i;
1ebb4b
@@ -870,12 +870,14 @@
1ebb4b
 	U32 u;
1ebb4b
 
1ebb4b
 	unsigned char* q;
1ebb4b
+	unsigned char* end;
1ebb4b
 
1ebb4b
 	for (u = 0; u < ((U32) bmp->width * (U32) bmp->height); u++) pixels[u] = 0;
1ebb4b
 
1ebb4b
 	byte = 0;
1ebb4b
 	x = 0;
1ebb4b
 	q = pixels;
1ebb4b
+	end = pixels + bmp->width * bmp->height;
1ebb4b
 
1ebb4b
 	for (y = 0; y < bmp->height; )
1ebb4b
 	{	count = ReadBlobByte (src);
1ebb4b
@@ -884,7 +886,10 @@
1ebb4b
 		{	/* Encoded mode. */
1ebb4b
 			byte = ReadBlobByte (src);
1ebb4b
 			for (i = 0; i < count; i++)
1ebb4b
-			{	if (compression == 1)
1ebb4b
+			{	
1ebb4b
+				if (q == end)
1ebb4b
+					return 0;
1ebb4b
+			 	if (compression == 1)
1ebb4b
 				{	(*(q++)) = (unsigned char) byte;
1ebb4b
 				}
1ebb4b
 				else
1ebb4b
@@ -896,13 +901,15 @@
1ebb4b
 		else
1ebb4b
 		{	/* Escape mode. */
1ebb4b
 			count = ReadBlobByte (src);
1ebb4b
-			if (count == 0x01) return;
1ebb4b
+			if (count == 0x01) return 1;
1ebb4b
 			switch (count)
1ebb4b
 			{
1ebb4b
 			case 0x00:
1ebb4b
 			 {	/* End of line. */
1ebb4b
 				x = 0;
1ebb4b
 				y++;
1ebb4b
+				if (y >= bmp->height)
1ebb4b
+					return 0;
1ebb4b
 				q = pixels + y * bmp->width;
1ebb4b
 				break;
1ebb4b
 			 }
1ebb4b
@@ -910,13 +917,20 @@
1ebb4b
 			 {	/* Delta mode. */
1ebb4b
 				x += ReadBlobByte (src);
1ebb4b
 				y += ReadBlobByte (src);
1ebb4b
+				if (y >= bmp->height)
1ebb4b
+					return 0;
1ebb4b
+				if (x >= bmp->width)
1ebb4b
+					return 0;
1ebb4b
 				q = pixels + y * bmp->width + x;
1ebb4b
 				break;
1ebb4b
 			 }
1ebb4b
 			default:
1ebb4b
 			 {	/* Absolute mode. */
1ebb4b
 				for (i = 0; i < count; i++)
1ebb4b
-				{	if (compression == 1)
1ebb4b
+				{
1ebb4b
+					if (q == end)
1ebb4b
+						return 0;
1ebb4b
+					if (compression == 1)
1ebb4b
 					{	(*(q++)) = ReadBlobByte (src);
1ebb4b
 					}
1ebb4b
 					else
1ebb4b
@@ -943,7 +957,7 @@
1ebb4b
 	byte = ReadBlobByte (src);  /* end of line */
1ebb4b
 	byte = ReadBlobByte (src);
1ebb4b
 
1ebb4b
-	return;
1ebb4b
+	return 1;
1ebb4b
 }
1ebb4b
 
1ebb4b
 /*
1ebb4b
@@ -1143,8 +1157,18 @@
1ebb4b
 		}
1ebb4b
 	}
1ebb4b
 	else
1ebb4b
-	{	/* Convert run-length encoded raster pixels. */
1ebb4b
-		DecodeImage (API,bmp,src,(unsigned int) bmp_info.compression,data->image);
1ebb4b
+	{
1ebb4b
+		if (bmp_info.bits_per_pixel == 8)	/* Convert run-length encoded raster pixels. */
1ebb4b
+		{
1ebb4b
+			if (!DecodeImage (API,bmp,src,(unsigned int) bmp_info.compression,data->image))
1ebb4b
+			{	WMF_ERROR (API,"corrupt bmp");
1ebb4b
+				API->err = wmf_E_BadFormat;
1ebb4b
+			}
1ebb4b
+		}
1ebb4b
+		else
1ebb4b
+		{	WMF_ERROR (API,"Unexpected pixel depth");
1ebb4b
+			API->err = wmf_E_BadFormat;
1ebb4b
+		}
1ebb4b
 	}
1ebb4b
 
1ebb4b
 	if (ERR (API))
1ebb4b
--- libwmf-0.2.8.4/src/ipa/ipa.h	2015-06-08 14:46:24.590876393 +0100
1ebb4b
+++ libwmf-0.2.8.4/src/ipa/ipa.h	2015-06-08 14:46:35.345993247 +0100
1ebb4b
@@ -48,7 +48,7 @@
1ebb4b
 static unsigned short ReadBlobLSBShort (BMPSource*);
1ebb4b
 static unsigned long  ReadBlobLSBLong (BMPSource*);
1ebb4b
 static long           TellBlob (BMPSource*);
1ebb4b
-static void           DecodeImage (wmfAPI*,wmfBMP*,BMPSource*,unsigned int,unsigned char*);
1ebb4b
+static int            DecodeImage (wmfAPI*,wmfBMP*,BMPSource*,unsigned int,unsigned char*);
1ebb4b
 static void           ReadBMPImage (wmfAPI*,wmfBMP*,BMPSource*);
1ebb4b
 static int            ExtractColor (wmfAPI*,wmfBMP*,wmfRGB*,unsigned int,unsigned int);
1ebb4b
 static void           SetColor (wmfAPI*,wmfBMP*,wmfRGB*,unsigned char,unsigned int,unsigned int);