]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
mupdftoraster - Added handling of empty input 191/head
authorJaiLuthra1 <luthrajaiji@gmail.com>
Mon, 20 Jan 2020 11:34:07 +0000 (17:04 +0530)
committerJaiLuthra1 <luthrajaiji@gmail.com>
Mon, 20 Jan 2020 11:34:07 +0000 (17:04 +0530)
filter/mupdftoraster.c

index 75e2f76566ad04363778407e79d0bee7f68baf10..09c66c00d7dce6d5d1c8de3bc21af6faf51e0c40 100644 (file)
@@ -62,7 +62,7 @@ typedef cups_page_header_t mupdf_page_header;
 #endif /* CUPS_RASTER_SYNCv1 */
 
 
-void
+int
 parse_doc_type(FILE *fp)
 {
   char buf[5];
@@ -71,13 +71,14 @@ parse_doc_type(FILE *fp)
   /* get the first few bytes of the file */
   rewind(fp);
   rc = fgets(buf,sizeof(buf),fp);
+  /* empty input */
   if (rc == NULL)
-    goto out;
+    return 1;
 
   /* is PDF */
   if (strncmp(buf,"%PDF",4) == 0)
-    return;
- out:
+    return 0;
+
   fprintf(stderr,"DEBUG: input file cannot be identified\n");
   exit(EXIT_FAILURE);
 }
@@ -245,6 +246,7 @@ main (int argc, char **argv, char *envp[])
   int cm_disabled;
   int n;
   int num_options;
+  int empty = 0;
   int status = 1;
   ppd_file_t *ppd = NULL;
   struct sigaction sa;
@@ -316,7 +318,8 @@ main (int argc, char **argv, char *envp[])
   }
 
   /* If doc type is not PDF exit */
-  parse_doc_type(fp);
+  if(parse_doc_type(fp))
+     empty = 1;
 
   /*  Check status of color management in CUPS */
   cm_calibrate = cmGetCupsColorCalibrateMode(options, num_options);
@@ -411,6 +414,12 @@ main (int argc, char **argv, char *envp[])
   /* call mutool */
   status = mutool_spawn (tmpstr, mupdf_args, envp);
   if (status != 0) status = 1;
+
+  if(empty)
+  {
+     fprintf(stderr, "DEBUG: Input is empty, outputting empty file.\n");
+     status = 0;
+  }
 out:
   if (fp)
     fclose(fp);