Line 0
Link Here
|
|
|
1 |
--- src/gd_tga.c.orig 2015-01-06 09:16:03 UTC |
2 |
+++ src/gd_tga.c |
3 |
@@ -285,14 +285,23 @@ int read_image_tga( gdIOCtx *ctx, oTga * |
4 |
buffer_caret = 0; |
5 |
|
6 |
while( bitmap_caret < image_block_size ) { |
7 |
- |
8 |
+ |
9 |
if ((decompression_buffer[buffer_caret] & TGA_RLE_FLAG) == TGA_RLE_FLAG) { |
10 |
encoded_pixels = ( ( decompression_buffer[ buffer_caret ] & 127 ) + 1 ); |
11 |
buffer_caret++; |
12 |
|
13 |
- for (i = 0; i < encoded_pixels; i++) { |
14 |
- for (j = 0; j < pixel_block_size; j++, bitmap_caret++) { |
15 |
- tga->bitmap[ bitmap_caret ] = decompression_buffer[ buffer_caret + j ]; |
16 |
+ if (encoded_pixels != 0) { |
17 |
+ |
18 |
+ if (!((buffer_caret + (encoded_pixels * pixel_block_size)) < image_block_size)) { |
19 |
+ gdFree( decompression_buffer ); |
20 |
+ gdFree( conversion_buffer ); |
21 |
+ return -1; |
22 |
+ } |
23 |
+ |
24 |
+ for (i = 0; i < encoded_pixels; i++) { |
25 |
+ for (j = 0; j < pixel_block_size; j++, bitmap_caret++) { |
26 |
+ tga->bitmap[ bitmap_caret ] = decompression_buffer[ buffer_caret + j ]; |
27 |
+ } |
28 |
} |
29 |
} |
30 |
buffer_caret += pixel_block_size; |
31 |
@@ -300,11 +309,20 @@ int read_image_tga( gdIOCtx *ctx, oTga * |
32 |
encoded_pixels = decompression_buffer[ buffer_caret ] + 1; |
33 |
buffer_caret++; |
34 |
|
35 |
- for (i = 0; i < encoded_pixels; i++) { |
36 |
- for( j = 0; j < pixel_block_size; j++, bitmap_caret++ ) { |
37 |
- tga->bitmap[ bitmap_caret ] = decompression_buffer[ buffer_caret + j ]; |
38 |
+ if (encoded_pixels != 0) { |
39 |
+ |
40 |
+ if (!((buffer_caret + (encoded_pixels * pixel_block_size)) < image_block_size)) { |
41 |
+ gdFree( decompression_buffer ); |
42 |
+ gdFree( conversion_buffer ); |
43 |
+ return -1; |
44 |
+ } |
45 |
+ |
46 |
+ for (i = 0; i < encoded_pixels; i++) { |
47 |
+ for( j = 0; j < pixel_block_size; j++, bitmap_caret++ ) { |
48 |
+ tga->bitmap[ bitmap_caret ] = decompression_buffer[ buffer_caret + j ]; |
49 |
+ } |
50 |
+ buffer_caret += pixel_block_size; |
51 |
} |
52 |
- buffer_caret += pixel_block_size; |
53 |
} |
54 |
} |
55 |
} |