]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libcupsfilters: Let filterChain() pass through data on empty chain
authorTill Kamppeter <till.kamppeter@gmail.com>
Sun, 14 Nov 2021 23:38:31 +0000 (00:38 +0100)
committerTill Kamppeter <till.kamppeter@gmail.com>
Sun, 14 Nov 2021 23:38:31 +0000 (00:38 +0100)
If the supplied filter chain does not contain any filter or only
filter entries with the filter function set to NULL, we pass the data
through unchanged now, we simply not applying any filters.

This can happen when the universal() filter function is called iwth
the same MIME type for the input and for the output format
supplied. In such a case we simply want the data passed through.

cupsfilters/filter.c

index d228e115f260f02080c8a6954c6acd21ca90ea95..3b9f5e2bca9de74e29ef0f8615cd780185ad1372 100644 (file)
@@ -454,6 +454,8 @@ filterChain(int inputfd,         /* I - File descriptor input stream */
                retval,              /* Return value */
                ret;
   int          infd, outfd;         /* Temporary file descriptors */
+  char          buf[4096];
+  ssize_t       bytes;
   cups_array_t *pids;               /* Executed filters array */
   filter_function_pid_t        *pid_entry,  /* Entry in executed filters array */
                key;                 /* Search key for filters */
@@ -487,6 +489,34 @@ filterChain(int inputfd,         /* I - File descriptor input stream */
                   filter->name ? filter->name : "Unspecified");
   }
 
+ /*
+  * Empty filter chain -> Pass through the data unchanged
+  */
+
+  if (cupsArrayCount(filter_chain) == 0)
+  {
+    if (log) log(ld, FILTER_LOGLEVEL_INFO,
+                "filterChain: No filter at all in chain, passing through the data.");
+    retval = 0;
+    while ((bytes = read(inputfd, buf, sizeof(buf))) > 0)
+      if (write(outputfd, buf, bytes) < bytes)
+      {
+       if (log) log(ld, FILTER_LOGLEVEL_ERROR,
+                    "filterChain: Data write error: %s", strerror(errno));
+       retval = 1;
+       break;
+      }
+    if (bytes < 0)
+    {
+      if (log) log(ld, FILTER_LOGLEVEL_ERROR,
+                    "filterChain: Data read error: %s", strerror(errno));
+      retval = 1;
+    }
+    close(inputfd);
+    close(outputfd);
+    return (retval);
+  }
+
  /*
   * Execute all of the filters...
   */