]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
foomatic-rip: Added handling of empty input 200/head
authorJaiLuthra1 <luthrajaiji@gmail.com>
Tue, 4 Feb 2020 11:21:58 +0000 (16:51 +0530)
committerJaiLuthra1 <luthrajaiji@gmail.com>
Tue, 4 Feb 2020 11:21:58 +0000 (16:51 +0530)
filter/foomatic-rip/foomaticrip.c
filter/foomatic-rip/pdf.c
filter/foomatic-rip/postscript.c

index 2c6cdb66152f8deb259c6f59226e346425293039..a1a4e9ea0d0952f52acc355d0d339cfeb04ee5d4 100644 (file)
@@ -576,6 +576,10 @@ int print_file(const char *filename, int convert)
     }
 
     n = fread_or_die(buf, 1, sizeof(buf) - 1, file);
+    if (!n){
+        _log("Input is empty, outputting empty file.\n");
+        return 1;
+    }
     buf[n] = '\0';
     type = guess_file_type(buf, n, &startpos);
     /* We do not use any JCL preceeded to the inputr data, as it is simply
index c79b56450045cb17d908252666b4114ee1de7f74..cc6f2ca062aae672ad5850d703012ad556f623ec 100644 (file)
@@ -42,7 +42,7 @@ static int wait_for_renderer();
 static int pdf_count_pages(const char *filename)
 {
     char gscommand[CMDLINE_MAX];
-    char output[31] = "";
+    char output[63] = "";
     int pagecount;
     size_t bytes;
 
@@ -55,11 +55,14 @@ static int pdf_count_pages(const char *filename)
     if (!pd)
       rip_die(EXIT_STARVED, "Failed to execute ghostscript to determine number of input pages!\n");
 
-    bytes = fread_or_die(output, 1, 31, pd);
+    bytes = fread_or_die(output, 1, 63, pd);
     pclose(pd);
 
     if (bytes <= 0 || sscanf(output, "PageCount: %d", &pagecount) < 1)
-      pagecount = -1;
+    {
+        if(bytes <= 0 || sscanf(output, "   **** Error: Too many pages in Page tree.\nPageCount: %d", &pagecount) < 1)
+        pagecount = -1;
+    }
 
     return pagecount;
 }
@@ -242,8 +245,13 @@ static int print_pdf_file(const char *filename)
 
     page_count = pdf_count_pages(filename);
 
-    if (page_count <= 0)
+    if (page_count < 0)
         rip_die(EXIT_JOBERR, "Unable to determine number of pages, page count: %d\n", page_count);
+    if (page_count == 0)
+    {
+        _log("No pages left, outputting empty file.\n");
+        return 1;
+    }
     _log("File contains %d pages\n", page_count);
 
     optionset_copy_values(optionset("header"), optionset("currentpage"));
index f0ddf0180b4ca6e7aa0200eb44e63bb2380acd07..8b6f0ad59f089f9f50647b56c199a2490032f244 100644 (file)
@@ -322,6 +322,7 @@ void _print_ps(stream_t *stream)
     pid_t rendererpid = 0;
     FILE *rendererhandle = NULL;
 
+    int empty = 1;
     int retval;
 
     dstr_t *tmp = create_dstr();
@@ -1009,6 +1010,7 @@ void _print_ps(stream_t *stream)
                         /* No renderer running, start it */
                         dstrcpy(tmp, psheader->data);
                         dstrcat(tmp, psfifo->data);
+                        empty = 0;
                         get_renderer_handle(tmp, &rendererhandle, &rendererpid);
                         /* psfifo is sent out, flush it */
                         dstrclear(psfifo);
@@ -1073,6 +1075,12 @@ void _print_ps(stream_t *stream)
 
     } while ((maxlines == 0 || linect < maxlines) && more_stuff != 0);
 
+    if (empty)
+    {
+        _log("No pages left, outputting empty file.\n");
+        return;
+    }
+
     /* Some buffer still containing data? Send it out to the renderer */
     if (more_stuff || inheader || !isempty(psfifo->data)) {
         /* Flush psfifo and send the remaining data to the renderer, this