Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

Printing not possible with line break or mis-interpreted encoding in job title #1988

Closed

Description

@michaelrsweet

Version: 1.2.4
CUPS.org User: till.kamppeter

Tested with Mandriva 2007/CUPS 1.2.4 and Ubuntu Edgy/CUPS 1.2.3 with current Debian patches.

See also

https://launchpad.net/distros/ubuntu/dapper/+source/cupsys/+bug/57445

especially my comments in the end.

This is a bug in /usr/lib/cups/filter/pstops.

To reproduce:

  1. Install gv, a screen viewer for PostScript (or use "kghostview").
  2. Create a PostScript file which does not contain a "%%Title:" line, either by printing from an appropriate application into a file (for example Firefox, document content does not matter) or by deleting this line from an existing PostScript file with a text editor.
  3. Type

cat file.ps | /usr/lib/cups/filter/pstops 1 user a 1 "" > result.ps
gv result.ps

You will see your PostScript file in a window. Close the window.

  1. Type

cat file.ps | /usr/lib/cups/filter/pstops 1 user 'a

and press . Then type

b' 1 "" > result.ps

and press again. You have made pstops now treating a job with the title "ab".

Do

gv result.ps

and you get an error.

So pstops cannot treat jobs whose titles have a newline inside, or where due to a misinterpreted encoding a byte of decimal value 13 (= ASCII value for newline) is not understood as part of a special character.

pstops should filter out the newlines and write all the text of the job title into one line.

I have used also a machine with CUPS 1.2.4 both as server and as client. for printing the example job of the Ubuntu report (see my test results there) and always could not print. Note that I printed from Firefox 1.5.x or 2.0beta (so encoding fixes in the command line clients have no effect, as these Firefox versions talk directly to the CUPS daemon). By printing to a file and then printing the file I could always print, as then no job title gets imposed to the job.

Activity

  1. michaelrsweet commented on Sep 26, 2006

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    Reassigning the priority... FWIW, in all the years we've done printing software, we have never had a user submit a job with a title containing a newline...

  2. michaelrsweet commented on Sep 27, 2006

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: till.kamppeter

    Probably usually no one submits jobs with newlines intendedly, as I did to investigate this bug. It is more that applications take some string related to the document and add it to the print job as the job title. Sometimes such a string can contain a newline, but more probably is that the job title given by the application program is a non-ASCII encoding, ISO 8859-X, chinese, ... if the CUPS daemon (more and more apps are linked to the CUPS library and talk directly to the CUPS daemon) does not auto-detect this encoding, a byte of decimal value 13 (ASCII code of newline) can be interpreted as line break.

    My suggestion is that, after the CUPS daemon has converted the job title to UTF-8 (or whatever encoding has to be used for the "%%Title:" line in the PostScript code) all non-printable characters (including newline) get stripped from the job title. If PostScript has a line length limit, the "%%Title:" line should be cut appropriately, too.

  3. michaelrsweet commented on Oct 2, 2006

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    Fixed in Subversion repository.

  4. michaelrsweet commented on Oct 2, 2006

    @michaelrsweet
    ContributorAuthor

    "str1988.patch":

    Index: imagetops.c

    --- imagetops.c (revision 5996)
    +++ imagetops.c (working copy)
    @@ -609,8 +609,8 @@
    puts("%%Creator: imagetops/" CUPS_SVERSION);
    strftime(curdate, sizeof(curdate), "%c", curtm);
    printf("%%%%CreationDate: %s\n", curdate);

    • printf("%%%%Title: %s\n", argv[3]);
    • printf("%%%%For: %s\n", argv[2]);
    • WriteTextComment("Title", argv[3]);
    • WriteTextComment("For", argv[2]);
      if (Orientation & 1)
      puts("%%Orientation: Landscape");
      else
      Index: texttops.c
      ===================================================================
      --- texttops.c (revision 5996)
      +++ texttops.c (working copy)
      @@ -208,8 +208,8 @@
      printf("%%cupsRotation: %d\n", (Orientation & 3) * 90);
      puts("%%Creator: texttops/" CUPS_SVERSION);
      printf("%%%%CreationDate: %s\n", curdate);
    • printf("%%%%Title: %s\n", title);
    • printf("%%%%For: %s\n", user);
    • WriteTextComment("Title", title);
    • WriteTextComment("For", user);
      puts("%%Pages: (atend)");

    /*

    Index: common.c

    --- common.c (revision 5996)
    +++ common.c (working copy)
    @@ -3,7 +3,7 @@
    *

    • Common filter routines for the Common UNIX Printing System (CUPS).
      *
    • * Copyright 1997-2005 by Easy Software Products.
    • * Copyright 1997-2006 by Easy Software Products.
      *
      • These coded instructions, statements, and computer programs are the
      • property of Easy Software Products and are protected by Federal
        @@ -28,6 +28,7 @@
      • SetCommonOptions() - Set common filter options for media size,
      •                    etc.
        
      • UpdatePageVars() - Update the page variables for the orientation.
    • * WriteComment() - Write a DSC comment.
      • WriteCommon() - Write common procedures...
      • WriteLabelProlog() - Write the prolog with the classification
      •                    and page label.
        
        @@ -46,30 +47,31 @@
      • Globals...
        */

    -int Orientation = 0, /* 0 = portrait, 1 = landscape, etc. */

    • Duplex = 0, /* Duplexed? */
    • LanguageLevel = 1, /* Language level of printer */
    • ColorDevice = 1; /* Do color text? /
      -float PageLeft = 18.0f, /
      Left margin */
    • PageRight = 594.0f, /* Right margin */
    • PageBottom = 36.0f, /* Bottom margin */
    • PageTop = 756.0f, /* Top margin */
    • PageWidth = 612.0f, /* Total page width */
    • PageLength = 792.0f; /* Total page length /
      +int Orientation = 0, /
      0 = portrait, 1 = landscape, etc. */
    • Duplex = 0, /* Duplexed? */
    • LanguageLevel = 1, /* Language level of printer */
    • ColorDevice = 1; /* Do color text? /
      +float PageLeft = 18.0f, /
      Left margin */
    • PageRight = 594.0f, /* Right margin */
    • PageBottom = 36.0f, /* Bottom margin */
    • PageTop = 756.0f, /* Top margin */
    • PageWidth = 612.0f, /* Total page width */
    • PageLength = 792.0f; /* Total page length */

    /*

    • 'SetCommonOptions()' - Set common filter options for media size, etc.
      */

    -ppd_file_t * /* O - PPD file /
    -SetCommonOptions(int num_options, /
    I - Number of options */

    •             cups_option_t _options,   /_ I - Options */
      
    •    int           change_size) /\* I - Change page size? _/
      
      +ppd_file_t * /_ O - PPD file */
      +SetCommonOptions(
    • int num_options, /* I - Number of options */
    • cups_option_t options, / I - Options */
    • int change_size) /* I - Change page size? */
      {
    • ppd_file_t ppd; / PPD file */
    • ppd_size_t pagesize; / Current page size */
    • const char val; / Option value */
    • ppd_file_t ppd; / PPD file */
    • ppd_size_t pagesize; / Current page size */
    • const char val; / Option value */

    #ifdef LC_TIME
    @@ -227,7 +229,7 @@
    void
    UpdatePageVars(void)
    {

    • float temp; /* Swapping variable */
    • float temp; /* Swapping variable */

    switch (Orientation & 3)
    @@ -467,5 +469,76 @@

    /*

    • * 'WriteTextComment()' - Write a DSC text comment.
    • /
      +
      +void
      +WriteTextComment(const char *name, /
      I - Comment name ("Title", etc.) */
    •             const char _value)    /_ I - Comment value */
      
      +{
    • int len; /* Current line length */
    • /*
    • * DSC comments are of the form:
    • * %%name: value
    • * The name and value must be limited to 7-bit ASCII for most printers,
    • * so we escape all non-ASCII and ASCII control characters as described
    • * in the Adobe Document Structuring Conventions specification.
    • */
    • printf("%%%%%s: (", name);
    • len = 5 + strlen(name);
    • while (*value)
    • {
    • if (*value < ' ' || *value >= 127)
    • {
    • /*
      
    •  \* Escape this character value...
      
    •  */
      
    •  if (len >= 251)          /\* Keep line < 254 chars */
      
    •    break;
      
    •  printf("\%03o", *value & 255);
      
    •  len += 4;
      
    • }
    • else if (*value == '')
    • {
    • /*
      
    •  \* Escape the backslash...
      
    •  */
      
    •  if (len >= 253)          /\* Keep line < 254 chars */
      
    •    break;
      
    •  putchar('\');
      
    •  putchar('\');
      
    •  len += 2;
      
    • }
    • else
    • {
    • /*
      
    •  \* Put this character literally...
      
    •  */
      
    •  if (len >= 254)          /\* Keep line < 254 chars */
      
    •    break;
      
    •  putchar(*value);
      
    •  len ++;
      
    • }
    • value ++;
    • }
    • puts(")");
      +}

    +/*

    • End of "$Id$".
      */
      Index: pstops.c

      --- pstops.c (revision 5996)
      +++ pstops.c (working copy)
      @@ -666,10 +666,10 @@
      fputs("ERROR: No %%Pages: comment in header!\n", stderr);

    if (!saw_for)

    • printf("%%%%For: %s\n", doc->user);
    • WriteTextComment("For", doc->user);

    if (!saw_title)

    • printf("%%%%Title: %s\n", doc->title);
    • WriteTextComment("Title", doc->title);

    if (doc->copies != 1 && (!doc->collate || !doc->slow_collate))
    {
    @@ -946,8 +946,8 @@
    else
    puts("%%Pages: 1");

    • printf("%%%%For: %s\n", doc->user);
    • printf("%%%%Title: %s\n", doc->title);
    • WriteTextComment("For", doc->user);
    • WriteTextComment("Title", doc->title);

    if (doc->copies != 1 && (!doc->collate || !doc->slow_collate))
    {

    Index: hpgl-prolog.c

    --- hpgl-prolog.c (revision 5996)
    +++ hpgl-prolog.c (working copy)
    @@ -70,8 +70,8 @@
    puts("%%Creator: hpgltops/" CUPS_SVERSION);
    strftime(line, sizeof(line), "%c", curtm);
    printf("%%%%CreationDate: %s\n", line);

    • printf("%%%%Title: %s\n", title);
    • printf("%%%%For: %s\n", user);
    • WriteTextComment("Title", title);
    • WriteTextComment("For", user);
      printf("%%cupsRotation: %d\n", (Orientation & 3) * 90);
      puts("%%EndComments");
      puts("%%BeginProlog");
      Index: common.h
      ===================================================================
      --- common.h (revision 5996)
      +++ common.h (working copy)
      @@ -3,7 +3,7 @@
    • Common filter definitions for the Common UNIX Printing System (CUPS).
      *

    • * Copyright 1997-2005 by Easy Software Products.

      • Copyright 1997-2006 by Easy Software Products.
      • These coded instructions, statements, and computer programs are the
      • property of Easy Software Products and are protected by Federal
        @@ -76,6 +76,7 @@
        extern void WriteLabelProlog(const char *label, float bottom,
        float top, float width);
        extern void WriteLabels(int orient);
        +extern void WriteTextComment(const char *name, const char *value);

      /*

  5. added this to the Stable milestone on Mar 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions