OpenPrinting / cups

OpenPrinting CUPS Sources
https://openprinting.github.io/cups
Apache License 2.0
1.05k stars 187 forks source link

PCL print jobs mistakenly detected as "ASCII" instead of `application/vnd.cups-raw` if header is too long #924

Closed olifre closed 5 months ago

olifre commented 6 months ago

Describe the bug PCL print jobs, e.g. by Windows systems using vendor drivers, are in some cases incorrectly not detected as mime type application/vnd.cups-raw since their LANGUAGE header may be beyond the 4096 character limit.

To Reproduce Steps to reproduce the behavior:

  1. Install a PCLv6 driver on a Windows 10 Pro / 11 Pro system, e.g. for Xerox multifunction devices, and use CUPS for printing.
  2. Print a document with long title, and / or have a lengthy username.
  3. Document is misdetected as ASCII and converted to PDF.

Expected behavior Document correctly detected as application/vnd.cups-raw.

Print job example

Header (> 4096 bytes) ``` %-12345X@PJL JOB @PJL XCPT @PJL XCPT @PJL XCPT @PJL XCPT @PJL XCPT automatic @PJL XCPT color @PJL XCPT 1 @PJL XCPT portrait @PJL XCPT automatic @PJL XCPT @PJL XCPT 3 @PJL XCPT @PJL XCPT ignore-pdl @PJL XCPT none @PJL XCPT automatic @PJL XCPT @PJL XCPT none @PJL XCPT @PJL XCPT @PJL XCPT offset-set @PJL XCPT @PJL XCPT @PJL XCPT none @PJL XCPT @PJL XCPT job-start-sheet @PJL XCPT @PJL XCPT @PJL XCPT automatic @PJL XCPT white @PJL XCPT @PJL XCPT 21000 @PJL XCPT 29700 @PJL XCPT @PJL XCPT system-default @PJL XCPT @PJL XCPT standard @PJL XCPT two-sided-long-edge @PJL XCPT @PJL XCPT none @PJL XCPT automatic @PJL XCPT automatic @PJL XCPT automatic @PJL XCPT collated @PJL XCPT use-local-printer-values @PJL XCPT @PJL XCPT @PJL XCPT windows-advanced-xcpt-filter @PJL XCPT chrome @PJL XCPT V4Driver 6.159.10.0 2015 Sep-1 20:28:09-04:00 | XeroxFilter 8.110.9.0V 2024.01.11 @PJL XCPT 123.0.6312.59 @PJL XCPT application/vnd.hp-PCLXL @PJL XCPT 8My Lengthy User Name 16261809 @PJL XCPT My Very Lengthy Document Title @PJL XCPT MyLengthyHostname @PJL XCPT My Lengthy User Name @PJL XCPT My Lengthy User Name @PJL XCPT @PJL XCPT @PJL ENTER LANGUAGE=PCLXL ) HP-PCL XL;2;1;Comment Copyright 2000-2015 Xerox Corporation. All Rights Reserved. white ```

System Information:

Additional context This issue seems to have become more common after Windows updates in the last weeks, likely more information is embedded into the XML before the "Enter Language" part. I am currently using the following .types dropin as a workaround:

application/postscript          ai eps ps string(0,%!) string(0,<04>%!) \
                                contains(0,128,<1B>%-12345X) + \
                                (contains(0,4096,"LANGUAGE=POSTSCRIPT") \
                                 contains(0,4096,"LANGUAGE = Postscript") \
                                 contains(0,4096,"LANGUAGE = PostScript") \
                                 contains(0,4096,"LANGUAGE = POSTSCRIPT") \
                                 (contains(0,4096,<0a>%!) + \
                                  !contains(0,4096,"ENTER LANGUAGE"))) \
                                contains(0,128,<1B>%-12345X) + \
                                (contains(4050,8000,"LANGUAGE=POSTSCRIPT") \
                                 contains(4050,8000,"LANGUAGE = Postscript") \
                                 contains(4050,8000,"LANGUAGE = PostScript") \
                                 contains(4050,8000,"LANGUAGE = POSTSCRIPT") \
                                 (contains(4050,8000,<0a>%!) + \
                                  !contains(4050,8000,"ENTER LANGUAGE")))

application/vnd.cups-raw        (string(0,<1B>E) + !string(2,<1B>%0B)) \
                                string(0,<1B>@) \
                                (contains(0,128,<1B>%-12345X) + \
                                 (contains(0,4096,"LANGUAGE=PCL") \
                                  contains(0,4096,"LANGUAGE = PCL"))) \
                                (contains(0,128,<1B>%-12345X) + \
                                 (contains(4050,8000,"LANGUAGE=PCL") \
                                  contains(4050,8000,"LANGUAGE = PCL")))

Issue can be reproduced by running cupsfilters on the (truncated) sample job file provided above.

michaelrsweet commented 6 months ago

Note: The current rule is for detecting PCL 3/4/5 and not PCL6/PCLXL. That there is more than 4k of header crap in the driver output just shows how bad the Windows drivers are...

That said, the added lines are incorrect - the second number in the "contains" is the length, not the last character position, so this can just be "4096" as for the originals...

olifre commented 6 months ago

Note: The current rule is for detecting PCL 3/4/5 and not PCL6/PCLXL. That there is more than 4k of header crap in the driver output just shows how bad the Windows drivers are...

Wholeheartedly agreed. If there was a working alternative for those printers on that OS...

That said, the added lines are incorrect - the second number in the "contains" is the length, not the last character position, so this can just be "4096" as for the originals...

Thanks! I'll fix that in my .types file.

michaelrsweet commented 5 months ago

I'm going to mark this one as a duplicate of #925 and we can address all of the mime.types issues there.