From 21c8209c52f53dd360bc4f4a7d2b0f49a1224363 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Sat, 27 Oct 2007 17:05:55 +0000 Subject: [PATCH] fixed handling of truncated ascii files. 2007-10-27 Sven Neumann * plug-ins/common/pnm.c (pnm_load_ascii): fixed handling of truncated ascii files. svn path=/trunk/; revision=23968 --- ChangeLog | 6 ++++++ plug-ins/common/pnm.c | 38 ++++++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index bb1ee6d2cf..875dbccdfe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ +2007-10-27 Sven Neumann + + * plug-ins/common/pnm.c (pnm_load_ascii): fixed handling of + truncated ascii files. + 2007-10-27 Sven Neumann * plug-ins/common/pnm.c: formatting. + (pnm_load_ascii): 2007-10-27 Sven Neumann diff --git a/plug-ins/common/pnm.c b/plug-ins/common/pnm.c index 382eee4034..4b348c4b47 100644 --- a/plug-ins/common/pnm.c +++ b/plug-ins/common/pnm.c @@ -602,11 +602,12 @@ pnm_load_ascii (PNMScanner *scan, PNMInfo *info, GimpPixelRgn *pixel_rgn) { - guchar *data, *d; - gint x, y, i, b; - gint start, end, scanlines; - gint np; - gchar buf[BUFLEN]; + guchar *data, *d; + gint x, y, i, b; + gint start, end, scanlines; + gint np; + gchar buf[BUFLEN]; + gboolean aborted = FALSE; np = (info->np) ? (info->np) : 1; /* No overflow as long as gimp_tile_height() < 2730 = 2^(31 - 18) / 3 */ @@ -615,12 +616,14 @@ pnm_load_ascii (PNMScanner *scan, /* Buffer reads to increase performance */ pnmscanner_createbuffer (scan, 4096); - for (y = 0; y < info->yres; ) + for (y = 0; y < info->yres; y += scanlines) { start = y; - end = y + gimp_tile_height (); - end = MIN (end, info->yres); + end = y + gimp_tile_height (); + end = MIN (end, info->yres); + scanlines = end - start; + d = data; for (i = 0; i < scanlines; i++) @@ -628,9 +631,22 @@ pnm_load_ascii (PNMScanner *scan, { for (b = 0; b < np; b++) { - /* Truncated files will just have all 0's at the end of the images */ + if (aborted) + { + d[b] = 0; + continue; + } + + /* Truncated files will just have all 0's + at the end of the images */ if (pnmscanner_eof (scan)) - g_message (_("Premature end of file.")); + { + g_message (_("Premature end of file.")); + aborted = TRUE; + + d[b] = 0; + continue; + } if (info->np) pnmscanner_gettoken (scan, buf, BUFLEN); @@ -662,8 +678,6 @@ pnm_load_ascii (PNMScanner *scan, gimp_progress_update ((double) y / (double) info->yres); gimp_pixel_rgn_set_rect (pixel_rgn, data, 0, y, info->xres, scanlines); - - y += scanlines; } gimp_progress_update (1.0);