]> granicus.if.org Git - openjpeg/commitdiff
[trunk] fixed pnmtoimage for odd pgm files (fixes issue 294)
authorMatthieu Darbois <mayeut@users.noreply.github.com>
Sat, 22 Nov 2014 14:09:16 +0000 (14:09 +0000)
committerMatthieu Darbois <mayeut@users.noreply.github.com>
Sat, 22 Nov 2014 14:09:16 +0000 (14:09 +0000)
src/bin/jp2/convert.c

index 7ada9a41208f36529df5a21c97c0fccc8d8ded76..47d8b0be7d01f14df910c39db21639a99b13d959 100644 (file)
@@ -1665,7 +1665,6 @@ static char *skip_idf(char *start, char out_idf[256])
 
 static void read_pnm_header(FILE *reader, struct pnm_header *ph)
 {
-    char *s;
     int format, have_wh, end, ttype;
     char idf[256], type[256];
     char line[256];
@@ -1691,6 +1690,8 @@ static void read_pnm_header(FILE *reader, struct pnm_header *ph)
 
     while(fgets(line, 250, reader))
     {
+        char *s;
+
         if(*line == '#') continue;
 
         s = line;
@@ -1774,7 +1775,18 @@ static void read_pnm_header(FILE *reader, struct pnm_header *ph)
             have_wh = 1;
 
             if(format == 1 || format == 4) break;
-
+                                       
+            if(format == 2 || format == 3 || format == 5 || format == 6)
+            {
+                if (skip_int(s, &ph->maxval) != NULL) {
+                    if(ph->maxval > 65535) {
+                        return;
+                    }
+                    else {
+                        break;
+                    }
+                }
+            }
             continue;
         }
         if(format == 2 || format == 3 || format == 5 || format == 6)