From a5173354d21186f62cc107b7a2c85b67b9f8d057 Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Tue, 7 May 2013 14:42:52 -0500 Subject: [PATCH] [libpng15] Check for EOF in contrib/pngminus/pnm2png.c (Paul Stewart). Ignore "#" delimited comments in input file to pnm2png.c. --- ANNOUNCE | 6 ++++-- CHANGES | 4 +++- contrib/pngminus/pnm2png.c | 19 ++++++++++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index d58faa837..188cabd8a 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,5 +1,5 @@ -Libpng 1.5.16beta05 - May 2, 2013 +Libpng 1.5.16beta05 - May 7, 2013 This is not intended to be a public release. It will be replaced within a few weeks by a public version or by another test version. @@ -46,7 +46,9 @@ Version 1.5.16beta04 [May 1, 2013] Expanded manual paragraph about writing private chunks, particularly the need to call png_set_keep_unknown_chunks() when writing them. -Version 1.5.16beta05 [May 2, 2013] +Version 1.5.16beta05 [May 7, 2013] + Check for EOF in contrib/pngminus/pnm2png.c (Paul Stewart). + Ignore "#" delimited comments in input file to pnm2png.c. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/CHANGES b/CHANGES index 1a3875324..607fd4ef3 100644 --- a/CHANGES +++ b/CHANGES @@ -4090,7 +4090,9 @@ Version 1.5.16beta04 [May 1, 2013] Expanded manual paragraph about writing private chunks, particularly the need to call png_set_keep_unknown_chunks() when writing them. -Version 1.5.16beta05 [May 2, 2013] +Version 1.5.16beta05 [May 7, 2013] + Check for EOF in contrib/pngminus/pnm2png.c (Paul Stewart). + Ignore "#" delimited comments in input file to pnm2png.c. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/contrib/pngminus/pnm2png.c b/contrib/pngminus/pnm2png.c index 4cdfad831..15eb48785 100644 --- a/contrib/pngminus/pnm2png.c +++ b/contrib/pngminus/pnm2png.c @@ -446,19 +446,32 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, void get_token(FILE *pnm_file, char *token) { int i = 0; + int ret; - /* remove white-space */ + /* remove white-space and comment lines */ do { - token[i] = (unsigned char) fgetc (pnm_file); + ret = fgetc(pnm_file); + if (ret == '#') { + /* the rest of this line is a comment */ + do + { + ret = fgetc(pnm_file); + } + while ((ret != '\n') && (ret != '\r') && (ret != EOF)); + } + if (ret == EOF) break; + token[i] = (unsigned char) ret; } while ((token[i] == '\n') || (token[i] == '\r') || (token[i] == ' ')); /* read string */ do { + ret = fgetc(pnm_file); + if (ret == EOF) break; i++; - token[i] = (unsigned char) fgetc (pnm_file); + token[i] = (unsigned char) ret; } while ((token[i] != '\n') && (token[i] != '\r') && (token[i] != ' '));