]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libcupsfilters: In universal() error on invalis input/output formats
authorTill Kamppeter <till.kamppeter@gmail.com>
Thu, 25 Nov 2021 18:11:21 +0000 (19:11 +0100)
committerTill Kamppeter <till.kamppeter@gmail.com>
Thu, 25 Nov 2021 18:11:21 +0000 (19:11 +0100)
If invalid input and/or output formats get provided as parameters, the
universal() flter function simply silently chooses valid formats
instead of erroring out. This is fixed with this commit.

cupsfilters/universal.c

index 3f10ecdc65773fdedcdd3dfd38f3cad4d64178c2..7ded792d70d1a42cc9ad8ea5f1e9a29d9859a78b 100644 (file)
@@ -30,6 +30,7 @@ universal(int inputfd,         /* I - File descriptor input stream */
   filter_input_output_format_t input_output_format;
   filter_logfunc_t log = data->logfunc;
   void *ld = data->logdata;
+  int ret = 0;
 
   input_output_format = *(filter_input_output_format_t *)parameters;
   input = input_output_format.input_format;
@@ -207,6 +208,12 @@ universal(int inputfd,         /* I - File descriptor input stream */
       if (log) log(ld, FILTER_LOGLEVEL_DEBUG,
                   "universal: Adding %s to chain", filter->name);
     }
+    else if (!strstr(input_type, "pdf"))
+    {
+      // Input format is not PDF and unknown -> Error
+      ret = 1;
+      goto out;
+    }
   }
   if (((strcmp(input_super, "image") &&
        strcmp(input_type, "vnd.adobe-reader-postscript")) ||
@@ -294,11 +301,25 @@ universal(int inputfd,         /* I - File descriptor input stream */
                       "universal: Adding %s to chain", filter->name);
          cupsArrayAdd(filter_chain, filter);
        }
+       else
+       {
+         // Output format is not PDF and unknown -> Error
+         ret = 1;
+         goto out;
+       }
       }
     }
   }
 
-  int ret = filterChain(inputfd, outputfd, inputseekable, data, filter_chain);
+ out:
+
+  if (ret) {
+    if (log) log(ld, FILTER_LOGLEVEL_ERROR,
+                "universal: Unsupported combination of input and output formats: %s -> %s",
+                input, output);
+  }
+  else
+    ret = filterChain(inputfd, outputfd, inputseekable, data, filter_chain);
 
   free(input_super);
   free(input_type);