After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 755988 - gtk printer dialog won't print jobs with names exceeding 255 characters
gtk printer dialog won't print jobs with names exceeding 255 characters
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Printing
3.18.x
Other Linux
: Normal minor
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2015-10-02 15:27 UTC by Felipe Borges
Modified: 2016-11-08 10:54 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gtkprintoperation: job names must not exceed 255 chars (1.31 KB, patch)
2015-10-02 15:28 UTC, Felipe Borges
none Details | Review
gtkprintoperation: job names must not exceed 255 chars (1.40 KB, patch)
2015-10-06 13:03 UTC, Felipe Borges
none Details | Review
test pdf (2.53 KB, application/pdf)
2015-10-06 13:05 UTC, Felipe Borges
  Details
gtkprintoperation: job names must not exceed 255 chars (1.79 KB, patch)
2015-10-07 13:08 UTC, Felipe Borges
none Details | Review
gtkprintoperation: job names must not exceed 255 chars (1.93 KB, patch)
2015-10-08 08:16 UTC, Felipe Borges
accepted-commit_now Details | Review

Description Felipe Borges 2015-10-02 15:27:51 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/
Comment 1 Felipe Borges 2015-10-02 15:28:34 UTC
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.
Comment 2 Matthias Clasen 2015-10-06 00:44:33 UTC
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.
Comment 3 Felipe Borges 2015-10-06 13:03:38 UTC
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.
Comment 4 Felipe Borges 2015-10-06 13:05:00 UTC
Created attachment 312730 [details]
test pdf

Thank you for your feedback, Matthias. I have been testing the patch with the pdf attached.
Comment 5 Matthias Clasen 2015-10-06 14:07:25 UTC
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
Comment 6 Matthias Clasen 2015-10-07 01:02:07 UTC
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).
Comment 7 Felipe Borges 2015-10-07 13:08:27 UTC
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.
Comment 8 Matthias Clasen 2015-10-08 03:23:05 UTC
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
Comment 9 Felipe Borges 2015-10-08 08:16:53 UTC
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.
Comment 10 Matthias Clasen 2015-10-08 20:25:59 UTC
Review of attachment 312892 [details] [review]:

looks good now