some cleanup to the error handling.
2007-07-05 Sven Neumann <sven@gimp.org> * plug-ins/common/psp.c: some cleanup to the error handling. svn path=/trunk/; revision=22878
This commit is contained in:

committed by
Sven Neumann

parent
3ab6e2b560
commit
1cccddcde6
@ -1,3 +1,7 @@
|
||||
2007-07-05 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* plug-ins/common/psp.c: some cleanup to the error handling.
|
||||
|
||||
2007-07-05 Raphaël Quinet <raphael@gimp.org>
|
||||
|
||||
* plug-ins/common/psd-load.c (do_layer_record): check for invalid
|
||||
|
@ -621,15 +621,11 @@ read_creator_block (FILE *f,
|
||||
|| fread (&length, 4, 1, f) < 1)
|
||||
{
|
||||
g_message ("Error reading creator keyword chunk");
|
||||
fclose (f);
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
if (memcmp (buf, "~FL\0", 4) != 0)
|
||||
{
|
||||
g_message ("Invalid keyword chunk header");
|
||||
fclose (f);
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
keyword = GUINT16_FROM_LE (keyword);
|
||||
@ -644,8 +640,6 @@ read_creator_block (FILE *f,
|
||||
if (fread (string, length, 1, f) < 1)
|
||||
{
|
||||
g_message ("Error reading creator keyword data");
|
||||
fclose (f);
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
switch (keyword)
|
||||
@ -669,8 +663,6 @@ read_creator_block (FILE *f,
|
||||
if (fread (&dword, 4, 1, f) < 1)
|
||||
{
|
||||
g_message ("Error reading creator keyword data");
|
||||
fclose (f);
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
switch (keyword)
|
||||
@ -688,7 +680,6 @@ read_creator_block (FILE *f,
|
||||
default:
|
||||
if (try_fseek (f, length, SEEK_CUR) < 0)
|
||||
{
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
@ -1022,7 +1013,7 @@ read_layer_block (FILE *f,
|
||||
long block_start, sub_block_start, channel_start;
|
||||
gint sub_id;
|
||||
guint32 sub_init_len, sub_total_len;
|
||||
gchar *name;
|
||||
gchar *name = NULL;
|
||||
guint16 namelen;
|
||||
guchar type, opacity, blend_mode, visibility, transparency_protected;
|
||||
guchar link_group_id, mask_linked, mask_disabled;
|
||||
@ -1047,16 +1038,12 @@ read_layer_block (FILE *f,
|
||||
/* Read the layer sub-block header */
|
||||
sub_id = read_block_header (f, &sub_init_len, &sub_total_len);
|
||||
if (sub_id == -1)
|
||||
{
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
|
||||
if (sub_id != PSP_LAYER_BLOCK)
|
||||
{
|
||||
g_message ("Invalid layer sub-block %s, should be LAYER",
|
||||
block_name (sub_id));
|
||||
fclose (f);
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1087,10 +1074,10 @@ read_layer_block (FILE *f,
|
||||
|| fread (&channel_count, 2, 1, f) < 1)
|
||||
{
|
||||
g_message ("Error reading layer information chunk");
|
||||
fclose (f);
|
||||
gimp_image_delete (image_ID);
|
||||
g_free (name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
name[namelen] = 0;
|
||||
type = PSP_LAYER_NORMAL; /* ??? */
|
||||
}
|
||||
@ -1098,6 +1085,7 @@ read_layer_block (FILE *f,
|
||||
{
|
||||
name = g_malloc (257);
|
||||
name[256] = 0;
|
||||
|
||||
if (fread (name, 256, 1, f) < 1
|
||||
|| fread (&type, 1, 1, f) < 1
|
||||
|| fread (&image_rect, 16, 1, f) < 1
|
||||
@ -1117,8 +1105,6 @@ read_layer_block (FILE *f,
|
||||
{
|
||||
g_message ("Error reading layer information chunk");
|
||||
g_free (name);
|
||||
fclose (f);
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -1151,8 +1137,6 @@ read_layer_block (FILE *f,
|
||||
|| ((width / 256) * (height / 256) >= 8192)) /* w * h < 2^29 */
|
||||
{
|
||||
g_message ("Invalid layer dimensions: %dx%d", width, height);
|
||||
fclose (f);
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1204,8 +1188,6 @@ read_layer_block (FILE *f,
|
||||
if (layer_ID == -1)
|
||||
{
|
||||
g_message ("Error creating layer");
|
||||
fclose (f);
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1225,16 +1207,17 @@ read_layer_block (FILE *f,
|
||||
if (major < 4)
|
||||
if (try_fseek (f, sub_block_start + sub_init_len, SEEK_SET) < 0)
|
||||
{
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pixel = g_malloc0 (height * width * bytespp);
|
||||
if (null_layer)
|
||||
pixels = NULL;
|
||||
{
|
||||
pixels = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
pixels = g_new(guchar *, height);
|
||||
pixels = g_new (guchar *, height);
|
||||
for (i = 0; i < height; i++)
|
||||
pixels[i] = pixel + width * bytespp * i;
|
||||
}
|
||||
@ -1260,8 +1243,6 @@ read_layer_block (FILE *f,
|
||||
{
|
||||
g_message ("Invalid layer sub-block %s, should be CHANNEL",
|
||||
block_name (sub_id));
|
||||
fclose (f);
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1276,8 +1257,6 @@ read_layer_block (FILE *f,
|
||||
|| fread (&channel_type, 2, 1, f) < 1)
|
||||
{
|
||||
g_message ("Error reading channel information chunk");
|
||||
fclose (f);
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1290,8 +1269,6 @@ read_layer_block (FILE *f,
|
||||
{
|
||||
g_message ("Invalid bitmap type %d in channel information chunk",
|
||||
bitmap_type);
|
||||
fclose (f);
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1299,8 +1276,6 @@ read_layer_block (FILE *f,
|
||||
{
|
||||
g_message ("Invalid channel type %d in channel information chunk",
|
||||
channel_type);
|
||||
fclose (f);
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1318,7 +1293,6 @@ read_layer_block (FILE *f,
|
||||
if (major < 4)
|
||||
if (try_fseek (f, channel_start + channel_init_len, SEEK_SET) < 0)
|
||||
{
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1326,13 +1300,11 @@ read_layer_block (FILE *f,
|
||||
if (read_channel_data (f, ia, pixels, bytespp,
|
||||
offset, drawable, compressed_len) == -1)
|
||||
{
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (try_fseek (f, channel_start + channel_total_len, SEEK_SET) < 0)
|
||||
{
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -1345,9 +1317,9 @@ read_layer_block (FILE *f,
|
||||
g_free (pixels);
|
||||
g_free (pixel);
|
||||
}
|
||||
|
||||
if (try_fseek (f, block_start + total_len, SEEK_SET) < 0)
|
||||
{
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1381,10 +1353,9 @@ read_tube_block (FILE *f,
|
||||
|| fread (&selection_mode, 4, 1, f) < 1)
|
||||
{
|
||||
g_message ("Error reading tube data chunk");
|
||||
fclose (f);
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
name[513] = 0;
|
||||
version = GUINT16_FROM_LE (version);
|
||||
params.step = GUINT32_FROM_LE (step_size);
|
||||
@ -1481,6 +1452,7 @@ load_image (const gchar *filename)
|
||||
fclose (f);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (memcmp (buf, "Paint Shop Pro Image File\n\032\0\0\0\0\0", 32) != 0)
|
||||
{
|
||||
g_message ("Incorrect file signature");
|
||||
@ -1490,6 +1462,7 @@ load_image (const gchar *filename)
|
||||
|
||||
major = GUINT16_FROM_LE (major);
|
||||
minor = GUINT16_FROM_LE (minor);
|
||||
|
||||
/* I only have the documentation for file format version 3.0,
|
||||
* but PSP 6 writes version 4.0. Let's hope it's backwards compatible.
|
||||
* Earlier versions probably don't have all the fields I expect
|
||||
@ -1548,7 +1521,10 @@ load_image (const gchar *filename)
|
||||
image_ID = gimp_image_new (ia.width, ia.height,
|
||||
ia.greyscale ? GIMP_GRAY : GIMP_RGB);
|
||||
if (image_ID == -1)
|
||||
return -1;
|
||||
{
|
||||
fclose (f);
|
||||
return -1;
|
||||
}
|
||||
|
||||
gimp_image_set_filename (image_ID, filename);
|
||||
|
||||
@ -1559,15 +1535,14 @@ load_image (const gchar *filename)
|
||||
if (block_number == 0)
|
||||
{
|
||||
g_message ("Missing General Image Attributes block");
|
||||
fclose (f);
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case PSP_CREATOR_BLOCK:
|
||||
if (read_creator_block (f, image_ID, block_total_len, &ia) == -1)
|
||||
return -1;
|
||||
goto error;
|
||||
break;
|
||||
|
||||
case PSP_COLOR_BLOCK:
|
||||
@ -1575,7 +1550,7 @@ load_image (const gchar *filename)
|
||||
|
||||
case PSP_LAYER_START_BLOCK:
|
||||
if (read_layer_block (f, image_ID, block_total_len, &ia) == -1)
|
||||
return -1;
|
||||
goto error;
|
||||
break;
|
||||
|
||||
case PSP_SELECTION_BLOCK:
|
||||
@ -1592,7 +1567,7 @@ load_image (const gchar *filename)
|
||||
|
||||
case PSP_TUBE_BLOCK:
|
||||
if (read_tube_block (f, image_ID, block_total_len, &ia) == -1)
|
||||
return -1;
|
||||
goto error;
|
||||
break;
|
||||
|
||||
case PSP_LAYER_BLOCK:
|
||||
@ -1613,15 +1588,14 @@ load_image (const gchar *filename)
|
||||
break;
|
||||
|
||||
if (try_fseek (f, block_start + block_total_len, SEEK_SET) < 0)
|
||||
{
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
}
|
||||
goto error;
|
||||
|
||||
block_number++;
|
||||
}
|
||||
|
||||
if (id == -1)
|
||||
{
|
||||
error:
|
||||
fclose (f);
|
||||
gimp_image_delete (image_ID);
|
||||
return -1;
|
||||
|
Reference in New Issue
Block a user