From 3ee9e7885bcee01a9dc8f79a1fa061ae33ce51c3 Mon Sep 17 00:00:00 2001 From: Till Kamppeter Date: Mon, 15 Nov 2021 00:38:31 +0100 Subject: [PATCH] libcupsfilters: Let filterChain() pass through data on empty chain 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 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cupsfilters/filter.c b/cupsfilters/filter.c index d228e115f..3b9f5e2bc 100644 --- a/cupsfilters/filter.c +++ b/cupsfilters/filter.c @@ -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... */ -- 2.47.3