GNOME Bugzilla – Bug 755988
gtk printer dialog won't print jobs with names exceeding 255 characters
Last modified: 2016-11-08 10:54:34 UTC
CUPS does not print jobs with names exceeding 255 chars. It is based on RFC 2911 section 4.1.2[0]. Since Gtk+ picks a default job name for unnamed jobs, I think we should truncate the job names in gtk_print_operation_set_job_name. To reproduce this bug, look at https://bugzilla.gnome.org/show_bug.cgi?id=741475 Evince arbitrarily sets a job name at https://git.gnome.org/browse/evince/tree/libview/ev-print-operation.c#n1634 [0] http://datatracker.ietf.org/doc/rfc2911/
Created attachment 312573 [details] [review] gtkprintoperation: job names must not exceed 255 chars According to http://datatracker.ietf.org/doc/rfc2911/, The 'name' attribute syntax is essentially the same as 'text', including the REQUIRED support of UTF-8 except that the sequence of characters is limited so that its encoded form MUST NOT exceed 255 (MAX) octets. CUPS will not print jobs with names exceeding 255 characters.
Review of attachment 312573 [details] [review]: ::: gtk/gtkprintoperation.c @@ +1620,3 @@ + * CUPS will not print jobs with names exceeding 255 chars. + */ + priv->job_name = g_strdup_printf ("%.*s", 255, job_name); This looks like it has the potential to wreak havoc with utf8 by cutting a multi-byte sequence in half.
Created attachment 312729 [details] [review] gtkprintoperation: job names must not exceed 255 chars According to http://datatracker.ietf.org/doc/rfc2911/, The 'name' attribute syntax is essentially the same as 'text', including the REQUIRED support of UTF-8 except that the sequence of characters is limited so that its encoded form MUST NOT exceed 255 (MAX) octets. CUPS will not print jobs with names exceeding 255 characters.
Created attachment 312730 [details] test pdf Thank you for your feedback, Matthias. I have been testing the patch with the pdf attached.
Review of attachment 312729 [details] [review]: ::: gtk/gtkprintoperation.c @@ +1623,3 @@ + priv->job_name = g_strdup (job_name); + else + priv->job_name = g_utf8_substring (job_name, 0, 255); Sadly, this is not the same thing at all. Now you are looking at character count, and restrict the string to at most 255 characters - which, depending on the region of the unicode space you're using, might be up to 1024 octets (ie bytes). What you need to do is cut the string off at 255 bytes, and then search backward to the last complete character from the end of the string. g_utf8_find_prev_char might be useful
your test pdf won't expose the problem I described, because it has an all-ascii name (ie no multi-byte utf8 sequences at all).
Created attachment 312820 [details] [review] gtkprintoperation: job names must not exceed 255 chars According to http://datatracker.ietf.org/doc/rfc2911/, The 'name' attribute syntax is essentially the same as 'text', including the REQUIRED support of UTF-8 except that the sequence of characters is limited so that its encoded form MUST NOT exceed 255 (MAX) octets. CUPS will not print jobs with names exceeding 255 characters.
Review of attachment 312820 [details] [review]: ::: gtk/gtkprintoperation.c @@ +1621,3 @@ + * CUPS will not print jobs with names exceeding 255 chars. + */ + end = g_utf8_find_prev_char (job_name, job_name + 255); Slight problem here: if job_name is shorter than 255, then this accesses memory beyond the end of the string. I guess you need a if (strlen (job_name) > 255) here
Created attachment 312892 [details] [review] gtkprintoperation: job names must not exceed 255 chars According to http://datatracker.ietf.org/doc/rfc2911/, The 'name' attribute syntax is essentially the same as 'text', including the REQUIRED support of UTF-8 except that the sequence of characters is limited so that its encoded form MUST NOT exceed 255 (MAX) octets. CUPS will not print jobs with names exceeding 255 characters.
Review of attachment 312892 [details] [review]: looks good now