mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-10 03:44:16 +00:00
Fixed a bug when loading some broken-GIF (the 'lzw_write_pixel' routine was called with pos < 0).
This commit is contained in:
parent
a408d8917b
commit
7939776b94
@ -1,3 +1,4 @@
|
|||||||
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -65,6 +66,7 @@ read_palette (FILE * file, GIF_PALETTE *palette)
|
|||||||
static int lzw_read_pixel (int pos, unsigned char *data)
|
static int lzw_read_pixel (int pos, unsigned char *data)
|
||||||
{
|
{
|
||||||
unsigned char *bitmap = data;
|
unsigned char *bitmap = data;
|
||||||
|
assert(pos >= 0);
|
||||||
return bitmap[pos];
|
return bitmap[pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,6 +75,8 @@ static int lzw_read_pixel (int pos, unsigned char *data)
|
|||||||
static void lzw_write_pixel (int pos, int c, unsigned char *data)
|
static void lzw_write_pixel (int pos, int c, unsigned char *data)
|
||||||
{
|
{
|
||||||
unsigned char *bitmap = data;
|
unsigned char *bitmap = data;
|
||||||
|
assert(pos >= 0);
|
||||||
|
assert(c >= 0 && c <= 255);
|
||||||
bitmap[pos] = c;
|
bitmap[pos] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,6 +276,8 @@ load_object (FILE * file, long size, void (*progress) (void *, float), void *dp)
|
|||||||
frame.yoff = fgetw (file);
|
frame.yoff = fgetw (file);
|
||||||
w = fgetw (file);
|
w = fgetw (file);
|
||||||
h = fgetw (file);
|
h = fgetw (file);
|
||||||
|
if (w < 1 || h < 1)
|
||||||
|
goto error;
|
||||||
bmp = calloc (w, h);
|
bmp = calloc (w, h);
|
||||||
if (!bmp)
|
if (!bmp)
|
||||||
goto error;
|
goto error;
|
||||||
@ -293,7 +299,8 @@ load_object (FILE * file, long size, void (*progress) (void *, float), void *dp)
|
|||||||
if (i & 64)
|
if (i & 64)
|
||||||
interlaced = 1;
|
interlaced = 1;
|
||||||
|
|
||||||
if (LZW_decode (file, lzw_write_pixel, bmp))
|
if (ferror (file) ||
|
||||||
|
LZW_decode (file, lzw_write_pixel, bmp))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (interlaced)
|
if (interlaced)
|
||||||
|
@ -98,12 +98,12 @@ LZW_decode (FILE * file,
|
|||||||
|
|
||||||
/* Expect to read clear code as first code here. */
|
/* Expect to read clear code as first code here. */
|
||||||
prev = read_code (file, buf, &bit_pos, bit_size);
|
prev = read_code (file, buf, &bit_pos, bit_size);
|
||||||
if (prev == -1)
|
if (prev == -1 || ferror (file))
|
||||||
return -1;
|
return -1;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
code = read_code (file, buf, &bit_pos, bit_size);
|
code = read_code (file, buf, &bit_pos, bit_size);
|
||||||
if (code == -1)
|
if (code == -1 || ferror (file))
|
||||||
return -1;
|
return -1;
|
||||||
if (code == clear_marker)
|
if (code == clear_marker)
|
||||||
{
|
{
|
||||||
@ -126,9 +126,13 @@ LZW_decode (FILE * file,
|
|||||||
|
|
||||||
/* Output the code. */
|
/* Output the code. */
|
||||||
out_pos += codes[c].len;
|
out_pos += codes[c].len;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
if (out_pos - i < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
write_pixel (out_pos - i, codes[c].c, data);
|
write_pixel (out_pos - i, codes[c].c, data);
|
||||||
if (codes[c].len)
|
if (codes[c].len)
|
||||||
c = codes[c].prefix;
|
c = codes[c].prefix;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user