JPWL: convert: Fix buffer overflow reading an image file less than four characters...
authorRobert Ancell <robert.ancell@gmail.com>
Sun, 17 Nov 2019 02:09:59 +0000 (15:09 +1300)
committerEven Rouault <even.rouault@spatialys.com>
Sun, 17 Nov 2019 02:09:59 +0000 (03:09 +0100)
Fixes #1068

src/bin/jpwl/convert.c

index 4f636c175fce408fa30b85cd32181195734e6a1c..e6feea50124a7dc3f1cd848350729faa70a61ede 100644 (file)
@@ -1488,7 +1488,7 @@ int imagetopgx(opj_image_t * image, const char *outfile)
         const size_t olen = strlen(outfile);
         const size_t dotpos = olen - 4;
         const size_t total = dotpos + 1 + 1 + 4; /* '-' + '[1-3]' + '.pgx' */
-        if (outfile[dotpos] != '.') {
+        if (olen < 4 || outfile[dotpos] != '.') {
             /* `pgx` was recognized but there is no dot at expected position */
             fprintf(stderr, "ERROR -> Impossible happen.");
             return 1;