forked from AuroraMiddleware/gtk
Add valid_ras_test and invalid_bmp_1.
* test-images.h: Add valid_ras_test and invalid_bmp_1. * test-loaders.c (main): Add random tests for ras and pnm and an invalid bmp which was a crasher until my 2002-03-12 commit. * io-pnm.c (gdk_pixbuf__pnm_image_load_increment): Don't unref the pixbuf on errors. * io-ras.c: Handle some errors.
This commit is contained in:
parent
166894bd8b
commit
5ebe8faab2
@ -1,3 +1,15 @@
|
|||||||
|
2002-03-13 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
|
* test-images.h: Add valid_ras_test and invalid_bmp_1.
|
||||||
|
|
||||||
|
* test-loaders.c (main): Add random tests for ras and pnm and an
|
||||||
|
invalid bmp which was a crasher until my 2002-03-12 commit.
|
||||||
|
|
||||||
|
* io-pnm.c (gdk_pixbuf__pnm_image_load_increment): Don't unref the
|
||||||
|
pixbuf on errors.
|
||||||
|
|
||||||
|
* io-ras.c: Handle some errors.
|
||||||
|
|
||||||
2002-03-12 Sven Neumann <sven@gimp.org>
|
2002-03-12 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* gdk-pixbuf.c (gdk_pixbuf_fill): use sequential writes instead of
|
* gdk-pixbuf.c (gdk_pixbuf_fill): use sequential writes instead of
|
||||||
|
@ -1013,8 +1013,6 @@ gdk_pixbuf__pnm_image_load_increment (gpointer data,
|
|||||||
if (retval == PNM_SUSPEND) {
|
if (retval == PNM_SUSPEND) {
|
||||||
break;
|
break;
|
||||||
} else if (retval == PNM_FATAL_ERR) {
|
} else if (retval == PNM_FATAL_ERR) {
|
||||||
if (context->pixbuf)
|
|
||||||
g_object_unref (context->pixbuf);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else if (retval == PNM_OK) {
|
} else if (retval == PNM_OK) {
|
||||||
/* send updated signal */
|
/* send updated signal */
|
||||||
|
@ -138,8 +138,9 @@ static GdkPixbuf *gdk_pixbuf__ras_image_load(FILE * f, GError **error)
|
|||||||
return pb;
|
return pb;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RAS2State(struct rasterfile *RAS,
|
static gboolean RAS2State(struct rasterfile *RAS,
|
||||||
struct ras_progressive_state *State)
|
struct ras_progressive_state *State,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
State->Header.width = GUINT32_FROM_BE(RAS->width);
|
State->Header.width = GUINT32_FROM_BE(RAS->width);
|
||||||
State->Header.height = GUINT32_FROM_BE(RAS->height);
|
State->Header.height = GUINT32_FROM_BE(RAS->height);
|
||||||
@ -148,47 +149,73 @@ static void RAS2State(struct rasterfile *RAS,
|
|||||||
State->Header.maptype = GUINT32_FROM_BE(RAS->maptype);
|
State->Header.maptype = GUINT32_FROM_BE(RAS->maptype);
|
||||||
State->Header.maplength = GUINT32_FROM_BE(RAS->maplength);
|
State->Header.maplength = GUINT32_FROM_BE(RAS->maplength);
|
||||||
|
|
||||||
g_assert(State->Header.maplength <= 768); /* Otherwise, we are in trouble */
|
if ((gint)State->Header.width <= 0 ||
|
||||||
|
(gint)State->Header.height <= 0 ||
|
||||||
|
State->Header.maplength > 768) {
|
||||||
|
g_set_error (error,
|
||||||
|
GDK_PIXBUF_ERROR,
|
||||||
|
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
||||||
|
_("RAS image has bogus header data"));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
State->RasType = State->Header.depth; /* This may be less trivial someday */
|
State->RasType = State->Header.depth; /* This may be less trivial someday */
|
||||||
State->HeaderSize = 32 + State->Header.maplength;
|
State->HeaderSize = 32 + State->Header.maplength;
|
||||||
|
|
||||||
if (State->RasType == 32)
|
if (State->RasType == 32)
|
||||||
State->LineWidth = State->Header.width * 4;
|
State->LineWidth = State->Header.width * 4;
|
||||||
if (State->RasType == 24)
|
else if (State->RasType == 24)
|
||||||
State->LineWidth = State->Header.width * 3;
|
State->LineWidth = State->Header.width * 3;
|
||||||
if (State->RasType == 8)
|
else if (State->RasType == 8)
|
||||||
State->LineWidth = State->Header.width * 1;
|
State->LineWidth = State->Header.width * 1;
|
||||||
if (State->RasType == 1) {
|
else if (State->RasType == 1) {
|
||||||
State->LineWidth = State->Header.width / 8;
|
State->LineWidth = State->Header.width / 8;
|
||||||
if ((State->Header.width & 7) != 0)
|
if ((State->Header.width & 7) != 0)
|
||||||
State->LineWidth++;
|
State->LineWidth++;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
g_set_error (error,
|
||||||
|
GDK_PIXBUF_ERROR,
|
||||||
|
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
||||||
|
_("RAS image has unknown type"));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Now padd the line to be a multiple of 16 bits */
|
/* Now pad the line to be a multiple of 16 bits */
|
||||||
if ((State->LineWidth & 1) != 0)
|
if ((State->LineWidth & 1) != 0)
|
||||||
State->LineWidth++;
|
State->LineWidth++;
|
||||||
|
|
||||||
if (State->LineBuf == NULL)
|
if (!State->LineBuf) {
|
||||||
State->LineBuf = g_malloc(State->LineWidth);
|
State->LineBuf = g_try_malloc (State->LineWidth);
|
||||||
|
|
||||||
g_assert(State->LineBuf != NULL);
|
if (!State->LineBuf) {
|
||||||
|
g_set_error (error,
|
||||||
|
GDK_PIXBUF_ERROR,
|
||||||
|
GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
|
||||||
|
_("Not enough memory to load RAS image"));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (State->pixbuf == NULL) {
|
if (!State->pixbuf) {
|
||||||
if (State->RasType == 32)
|
if (State->RasType == 32)
|
||||||
State->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE,
|
State->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
|
||||||
8,
|
(gint) State->Header.width,
|
||||||
(gint)
|
(gint) State->Header.height);
|
||||||
State->Header.width,
|
|
||||||
(gint)
|
|
||||||
State->Header.
|
|
||||||
height);
|
|
||||||
else
|
else
|
||||||
State->pixbuf =
|
State->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
|
||||||
gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,
|
(gint) State->Header.width,
|
||||||
(gint) State->Header.width,
|
(gint) State->Header.height);
|
||||||
(gint) State->Header.height);
|
|
||||||
|
if (!State->pixbuf) {
|
||||||
|
g_set_error (error,
|
||||||
|
GDK_PIXBUF_ERROR,
|
||||||
|
GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
|
||||||
|
_("Not enough memory to load RAS image"));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (State->prepared_func != NULL)
|
if (State->prepared_func != NULL)
|
||||||
/* Notify the client that we are ready to go */
|
/* Notify the client that we are ready to go */
|
||||||
(*State->prepared_func) (State->pixbuf,
|
(*State->prepared_func) (State->pixbuf,
|
||||||
@ -197,7 +224,7 @@ static void RAS2State(struct rasterfile *RAS,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((State->Header.maplength==0)&&(State->RasType==1)) {
|
if ((State->Header.maplength == 0) && (State->RasType == 1)) {
|
||||||
State->HeaderBuf[32] = 255;
|
State->HeaderBuf[32] = 255;
|
||||||
State->HeaderBuf[33] = 0;
|
State->HeaderBuf[33] = 0;
|
||||||
State->HeaderBuf[34] = 255;
|
State->HeaderBuf[34] = 255;
|
||||||
@ -206,6 +233,7 @@ static void RAS2State(struct rasterfile *RAS,
|
|||||||
State->HeaderBuf[37] = 0;
|
State->HeaderBuf[37] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -362,6 +390,9 @@ static void OneLine1(struct ras_progressive_state *context)
|
|||||||
|
|
||||||
static void OneLine(struct ras_progressive_state *context)
|
static void OneLine(struct ras_progressive_state *context)
|
||||||
{
|
{
|
||||||
|
context->LineDone = 0;
|
||||||
|
if (context->Lines >= context->Header.height)
|
||||||
|
return;
|
||||||
if (context->RasType == 32)
|
if (context->RasType == 32)
|
||||||
OneLine32(context);
|
OneLine32(context);
|
||||||
if (context->RasType == 24)
|
if (context->RasType == 24)
|
||||||
@ -372,8 +403,6 @@ static void OneLine(struct ras_progressive_state *context)
|
|||||||
OneLine1(context);
|
OneLine1(context);
|
||||||
|
|
||||||
context->LineDone = 0;
|
context->LineDone = 0;
|
||||||
if (context->Lines > context->Header.height)
|
|
||||||
return;
|
|
||||||
context->Lines++;
|
context->Lines++;
|
||||||
|
|
||||||
if (context->updated_func != NULL) {
|
if (context->updated_func != NULL) {
|
||||||
@ -392,7 +421,7 @@ static void OneLine(struct ras_progressive_state *context)
|
|||||||
* buf - new image data
|
* buf - new image data
|
||||||
* size - length of new image data
|
* size - length of new image data
|
||||||
*
|
*
|
||||||
* append image data onto inrecrementally built output image
|
* append image data onto incrementally built output image
|
||||||
*/
|
*/
|
||||||
static gboolean
|
static gboolean
|
||||||
gdk_pixbuf__ras_image_load_increment(gpointer data,
|
gdk_pixbuf__ras_image_load_increment(gpointer data,
|
||||||
@ -443,8 +472,10 @@ gdk_pixbuf__ras_image_load_increment(gpointer data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (context->HeaderDone >= 32)
|
if (context->HeaderDone >= 32)
|
||||||
RAS2State((struct rasterfile *) context->HeaderBuf,
|
if (!RAS2State((struct rasterfile *) context->HeaderBuf,
|
||||||
context);
|
context, error)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -460,3 +491,4 @@ gdk_pixbuf__ras_fill_vtable (GdkPixbufModule *module)
|
|||||||
module->stop_load = gdk_pixbuf__ras_image_stop_load;
|
module->stop_load = gdk_pixbuf__ras_image_stop_load;
|
||||||
module->load_increment = gdk_pixbuf__ras_image_load_increment;
|
module->load_increment = gdk_pixbuf__ras_image_load_increment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
@ -358,10 +358,6 @@ main (int argc, char **argv)
|
|||||||
{
|
{
|
||||||
int seed;
|
int seed;
|
||||||
|
|
||||||
/* Set a malloc which emulates low mem */
|
|
||||||
max_allocation = G_MAXINT;
|
|
||||||
g_mem_set_vtable (&limited_table);
|
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
seed = atoi (argv[1]);
|
seed = atoi (argv[1]);
|
||||||
else
|
else
|
||||||
@ -370,6 +366,10 @@ main (int argc, char **argv)
|
|||||||
write_seed (seed);
|
write_seed (seed);
|
||||||
}
|
}
|
||||||
g_random_set_seed (seed);
|
g_random_set_seed (seed);
|
||||||
|
|
||||||
|
/* Set a malloc which emulates low mem */
|
||||||
|
max_allocation = G_MAXINT;
|
||||||
|
g_mem_set_vtable (&limited_table);
|
||||||
|
|
||||||
g_type_init ();
|
g_type_init ();
|
||||||
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
|
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
|
||||||
@ -411,7 +411,7 @@ main (int argc, char **argv)
|
|||||||
TEST (tiff1_test_1, FALSE);
|
TEST (tiff1_test_1, FALSE);
|
||||||
TEST (tiff1_test_2, FALSE);
|
TEST (tiff1_test_2, FALSE);
|
||||||
#if 0
|
#if 0
|
||||||
TEST (tiff1_test_3, FALSE); /* Segfault in TIFFReadDirectory with libtiff 3.5.5, fixed in 3.5.7 */
|
TEST (tiff1_test_3, FALSE); /* Segfault in TIFFReadDirectory */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEST (valid_tga_test, TRUE);
|
TEST (valid_tga_test, TRUE);
|
||||||
@ -421,7 +421,11 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
TEST (wbmp_test_1, FALSE);
|
TEST (wbmp_test_1, FALSE);
|
||||||
TEST (wbmp_test_2, FALSE);
|
TEST (wbmp_test_2, FALSE);
|
||||||
|
|
||||||
|
TEST (invalid_bmp_1, FALSE);
|
||||||
|
|
||||||
|
TEST (valid_ras_test, TRUE);
|
||||||
|
|
||||||
TEST_RANDOM (GIF_HEADER, 150, FALSE);
|
TEST_RANDOM (GIF_HEADER, 150, FALSE);
|
||||||
TEST_RANDOM (PNG_HEADER, 1100, FALSE);
|
TEST_RANDOM (PNG_HEADER, 1100, FALSE);
|
||||||
TEST_RANDOM (JPEG_HEADER, 800, FALSE);
|
TEST_RANDOM (JPEG_HEADER, 800, FALSE);
|
||||||
@ -435,8 +439,9 @@ main (int argc, char **argv)
|
|||||||
TEST_RANDOM (BMP_HEADER, 150, FALSE);
|
TEST_RANDOM (BMP_HEADER, 150, FALSE);
|
||||||
#define XPM_HEADER '/', '*', ' ', 'X', 'P', 'M', ' ', '*', '/'
|
#define XPM_HEADER '/', '*', ' ', 'X', 'P', 'M', ' ', '*', '/'
|
||||||
TEST_RANDOM (XPM_HEADER, 150, FALSE);
|
TEST_RANDOM (XPM_HEADER, 150, FALSE);
|
||||||
|
#define RAS_HEADER 0x59, 0xA6, 0x6A, 0x95
|
||||||
|
TEST_RANDOM (RAS_HEADER, 300, FALSE);
|
||||||
|
|
||||||
TEST_RANDOMLY_MODIFIED (valid_tiff1_test, FALSE);
|
TEST_RANDOMLY_MODIFIED (valid_tiff1_test, FALSE);
|
||||||
TEST_RANDOMLY_MODIFIED (valid_gif_test, FALSE);
|
TEST_RANDOMLY_MODIFIED (valid_gif_test, FALSE);
|
||||||
TEST_RANDOMLY_MODIFIED (valid_png_test, FALSE);
|
TEST_RANDOMLY_MODIFIED (valid_png_test, FALSE);
|
||||||
@ -445,8 +450,9 @@ main (int argc, char **argv)
|
|||||||
TEST_RANDOMLY_MODIFIED (valid_ico_test, FALSE);
|
TEST_RANDOMLY_MODIFIED (valid_ico_test, FALSE);
|
||||||
TEST_RANDOMLY_MODIFIED (valid_bmp_test, FALSE);
|
TEST_RANDOMLY_MODIFIED (valid_bmp_test, FALSE);
|
||||||
TEST_RANDOMLY_MODIFIED (valid_xpm_test, FALSE);
|
TEST_RANDOMLY_MODIFIED (valid_xpm_test, FALSE);
|
||||||
|
TEST_RANDOMLY_MODIFIED (valid_ras_test, FALSE);
|
||||||
|
TEST_RANDOMLY_MODIFIED (valid_ppm_4, FALSE);
|
||||||
|
|
||||||
|
|
||||||
/* memory tests */
|
/* memory tests */
|
||||||
|
|
||||||
/* How do the loaders behave when memory is low?
|
/* How do the loaders behave when memory is low?
|
||||||
|
Loading…
Reference in New Issue
Block a user