OpenPrinting / cups

OpenPrinting CUPS Sources
https://openprinting.github.io/cups
Apache License 2.0
967 stars 177 forks source link

backend/ipp.c: Fix printing jobs with long names on older IPP printers #866

Closed zdohnal closed 6 months ago

zdohnal commented 6 months ago

On older printers (ones which don't support IPP operation Create-Job) we concatenate job number and title into one string, which we use as IPP attribute job-name. If the original title was almost 255 chars, the joining the strings will overflow maximal required length for this attribute, and Validate-Job fails.

We could check whether the string is longer than 255 and cut it, but I chose to shrink the buffer to 256, since we already use snprintf() which will cut the string and put null terminator for us.

Fixes #644

zdohnal commented 6 months ago

@michaelrsweet hmm, good point! Should we transcode it via cupsUTF8ToCharset()?

michaelrsweet commented 6 months ago

@michaelrsweet hmm, good point! Should we transcode it via cupsUTF8ToCharset()?

No, but we might want to implement a "smart" snprintf that can safely truncate UTF-8 at some point...

zdohnal commented 6 months ago

@michaelrsweet I've added a note about UTF-8, so we know there might be problem in the future.

jsmeix commented 6 months ago

@zdohnal only as a side note FYI what had happened in the past with invalid UTF-8 data together with a badly compiled D-Bus library see https://github.com/apple/cups/issues/5143

In the end the generic root of this evil is that a program (e.g. cupsd) loses control when it calls a function from a third-party library (e.g. libdbus) so most programs are most of the time out of control ;-)

zdohnal commented 6 months ago

@jsmeix looks interesting :) but at least we can do our best effort when we can :D