Various loader fixes (Marcus Meissner, bug 494).

SVN revision: 34853
This commit is contained in:
Kim Woelders 2008-06-18 17:52:38 +00:00
parent a6fa566a3d
commit 78037c5c76
5 changed files with 17 additions and 6 deletions

View File

@ -10,7 +10,7 @@ char
load(ImlibImage * im, ImlibProgressFunction progress, load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load) char progress_granularity, char immediate_load)
{ {
int w, h, alpha; int w = 0, h = 0, alpha = 0;
FILE *f; FILE *f;
if (im->data) if (im->data)
@ -23,11 +23,13 @@ load(ImlibImage * im, ImlibProgressFunction progress,
{ {
char buf[256], buf2[256]; char buf[256], buf2[256];
buf[0] = '\0';
if (!fgets(buf, 255, f)) if (!fgets(buf, 255, f))
{ {
fclose(f); fclose(f);
return 0; return 0;
} }
buf2[0] = '\0';
sscanf(buf, "%s %i %i %i", buf2, &w, &h, &alpha); sscanf(buf, "%s %i %i %i", buf2, &w, &h, &alpha);
if (strcmp(buf2, "ARGB")) if (strcmp(buf2, "ARGB"))
{ {

View File

@ -565,7 +565,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
unsigned char *buffer_end_minus_1 = buffer_end - 1; unsigned char *buffer_end_minus_1 = buffer_end - 1;
x = 0; x = 0;
y = 0; y = 0;
for (i = 0; i < imgsize && buffer_ptr < buffer_end_minus_1 && g; i++) for (i = 0; i < imgsize && buffer_ptr < buffer_end_minus_1; i++)
{ {
byte1 = buffer_ptr[0]; byte1 = buffer_ptr[0];
byte2 = buffer_ptr[1]; byte2 = buffer_ptr[1];

View File

@ -78,6 +78,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
im->h = h = cinfo.output_height; im->h = h = cinfo.output_height;
if ((w < 1) || (h < 1) || (w > 8192) || (h > 8192)) if ((w < 1) || (h < 1) || (w > 8192) || (h > 8192))
{ {
im->w = im->h = 0;
jpeg_destroy_decompress(&cinfo); jpeg_destroy_decompress(&cinfo);
fclose(f); fclose(f);
return 0; return 0;
@ -96,6 +97,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if (cinfo.rec_outbuf_height > 16) if (cinfo.rec_outbuf_height > 16)
{ {
im->w = im->h = 0;
jpeg_destroy_decompress(&cinfo); jpeg_destroy_decompress(&cinfo);
fclose(f); fclose(f);
return 0; return 0;
@ -103,6 +105,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
data = malloc(w * 16 * 3); data = malloc(w * 16 * 3);
if (!data) if (!data)
{ {
im->w = im->h = 0;
jpeg_destroy_decompress(&cinfo); jpeg_destroy_decompress(&cinfo);
fclose(f); fclose(f);
return 0; return 0;
@ -111,6 +114,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
ptr2 = im->data = malloc(w * h * sizeof(DATA32)); ptr2 = im->data = malloc(w * h * sizeof(DATA32));
if (!im->data) if (!im->data)
{ {
im->w = im->h = 0;
free(data); free(data);
jpeg_destroy_decompress(&cinfo); jpeg_destroy_decompress(&cinfo);
fclose(f); fclose(f);

View File

@ -437,6 +437,7 @@ ILBM ilbm;
} }
} }
if (!full || !ok) { if (!full || !ok) {
im->w = im->h = 0;
freeilbm(&ilbm); freeilbm(&ilbm);
return ok; return ok;
} }
@ -452,11 +453,11 @@ ILBM ilbm;
plane[0] = NULL; plane[0] = NULL;
im->data = malloc(im->w * im->h * sizeof(DATA32)); im->data = malloc(im->w * im->h * sizeof(DATA32));
if (im->data) { n = ilbm.depth;
n = ilbm.depth; plane[0] = malloc(((im->w + 15) / 16) * 2 * n);
if (im->data && plane[0]) {
if (ilbm.mask == 1) n++; if (ilbm.mask == 1) n++;
plane[0] = malloc(((im->w + 15) / 16) * 2 * n);
for (i = 1; i < n; i++) plane[i] = plane[i - 1] + ((im->w + 15) / 16) * 2; for (i = 1; i < n; i++) plane[i] = plane[i - 1] + ((im->w + 15) / 16) * 2;
z = ((im->w + 15) / 16) * 2 * n; z = ((im->w + 15) / 16) * 2 * n;
@ -492,9 +493,10 @@ ILBM ilbm;
/*---------- /*----------
* We either had a successful decode, the user cancelled, or we couldn't get * We either had a successful decode, the user cancelled, or we couldn't get
* the memory for im->data. * the memory for im->data or plane[0].
*----------*/ *----------*/
if (!ok) { if (!ok) {
im->w = im->h = 0;
if (im->data) free(im->data); if (im->data) free(im->data);
im->data = NULL; im->data = NULL;
} }

View File

@ -153,6 +153,9 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity,
pixels = 0; pixels = 0;
count = 0; count = 0;
line = malloc(lsz); line = malloc(lsz);
if (!line)
return NULL;
backslash = 0; backslash = 0;
memset(lookup, 0, sizeof(lookup)); memset(lookup, 0, sizeof(lookup));
while (!done) while (!done)