Lines 1-111
Link Here
|
1 |
diff -ru src/ipa/ipa/bmp.h src/ipa/ipa/bmp.h |
|
|
2 |
--- src/ipa/ipa/bmp.h 2015-06-03 09:30:59.410501271 +0100 |
3 |
+++ src/ipa/ipa/bmp.h 2015-06-03 09:31:05.775572630 +0100 |
4 |
@@ -859,7 +859,7 @@ |
5 |
% |
6 |
% |
7 |
*/ |
8 |
-static void DecodeImage (wmfAPI* API,wmfBMP* bmp,BMPSource* src,unsigned int compression,unsigned char* pixels) |
9 |
+static int DecodeImage (wmfAPI* API,wmfBMP* bmp,BMPSource* src,unsigned int compression,unsigned char* pixels) |
10 |
{ int byte; |
11 |
int count; |
12 |
int i; |
13 |
@@ -870,12 +870,14 @@ |
14 |
U32 u; |
15 |
|
16 |
unsigned char* q; |
17 |
+ unsigned char* end; |
18 |
|
19 |
for (u = 0; u < ((U32) bmp->width * (U32) bmp->height); u++) pixels[u] = 0; |
20 |
|
21 |
byte = 0; |
22 |
x = 0; |
23 |
q = pixels; |
24 |
+ end = pixels + bmp->width * bmp->height; |
25 |
|
26 |
for (y = 0; y < bmp->height; ) |
27 |
{ count = ReadBlobByte (src); |
28 |
@@ -884,7 +886,10 @@ |
29 |
{ /* Encoded mode. */ |
30 |
byte = ReadBlobByte (src); |
31 |
for (i = 0; i < count; i++) |
32 |
- { if (compression == 1) |
33 |
+ { |
34 |
+ if (q == end) |
35 |
+ return 0; |
36 |
+ if (compression == 1) |
37 |
{ (*(q++)) = (unsigned char) byte; |
38 |
} |
39 |
else |
40 |
@@ -896,13 +901,15 @@ |
41 |
else |
42 |
{ /* Escape mode. */ |
43 |
count = ReadBlobByte (src); |
44 |
- if (count == 0x01) return; |
45 |
+ if (count == 0x01) return 1; |
46 |
switch (count) |
47 |
{ |
48 |
case 0x00: |
49 |
{ /* End of line. */ |
50 |
x = 0; |
51 |
y++; |
52 |
+ if (y >= bmp->height) |
53 |
+ return 0; |
54 |
q = pixels + y * bmp->width; |
55 |
break; |
56 |
} |
57 |
@@ -910,13 +917,20 @@ |
58 |
{ /* Delta mode. */ |
59 |
x += ReadBlobByte (src); |
60 |
y += ReadBlobByte (src); |
61 |
+ if (y >= bmp->height) |
62 |
+ return 0; |
63 |
+ if (x >= bmp->width) |
64 |
+ return 0; |
65 |
q = pixels + y * bmp->width + x; |
66 |
break; |
67 |
} |
68 |
default: |
69 |
{ /* Absolute mode. */ |
70 |
for (i = 0; i < count; i++) |
71 |
- { if (compression == 1) |
72 |
+ { |
73 |
+ if (q == end) |
74 |
+ return 0; |
75 |
+ if (compression == 1) |
76 |
{ (*(q++)) = ReadBlobByte (src); |
77 |
} |
78 |
else |
79 |
@@ -943,7 +957,7 @@ |
80 |
byte = ReadBlobByte (src); /* end of line */ |
81 |
byte = ReadBlobByte (src); |
82 |
|
83 |
- return; |
84 |
+ return 1; |
85 |
} |
86 |
|
87 |
/* |
88 |
@@ -1146,7 +1160,10 @@ |
89 |
{ |
90 |
if (bmp_info.bits_per_pixel == 8) /* Convert run-length encoded raster pixels. */ |
91 |
{ |
92 |
- DecodeImage (API,bmp,src,(unsigned int) bmp_info.compression,data->image); |
93 |
+ if (!DecodeImage (API,bmp,src,(unsigned int) bmp_info.compression,data->image)) |
94 |
+ { WMF_ERROR (API,"corrupt bmp"); |
95 |
+ API->err = wmf_E_BadFormat; |
96 |
+ } |
97 |
} |
98 |
else |
99 |
{ WMF_ERROR (API,"Unexpected pixel depth"); |
100 |
diff -ru src/ipa/ipa.h src/ipa/ipa.h |
101 |
--- src/ipa/ipa.h 2015-06-03 09:30:59.410501271 +0100 |
102 |
+++ src/ipa/ipa.h 2015-06-03 09:31:08.687605277 +0100 |
103 |
@@ -48,7 +48,7 @@ |
104 |
static unsigned short ReadBlobLSBShort (BMPSource*); |
105 |
static unsigned long ReadBlobLSBLong (BMPSource*); |
106 |
static long TellBlob (BMPSource*); |
107 |
-static void DecodeImage (wmfAPI*,wmfBMP*,BMPSource*,unsigned int,unsigned char*); |
108 |
+static int DecodeImage (wmfAPI*,wmfBMP*,BMPSource*,unsigned int,unsigned char*); |
109 |
static void ReadBMPImage (wmfAPI*,wmfBMP*,BMPSource*); |
110 |
static int ExtractColor (wmfAPI*,wmfBMP*,wmfRGB*,unsigned int,unsigned int); |
111 |
static void SetColor (wmfAPI*,wmfBMP*,wmfRGB*,unsigned char,unsigned int,unsigned int); |