Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

zdohnal
Copy link
Member

@zdohnal zdohnal commented Jan 15, 2024

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 zdohnal requested a review from michaelrsweet January 15, 2024 16:06
michaelrsweet
michaelrsweet previously approved these changes Jan 15, 2024
Copy link
Member

@michaelrsweet michaelrsweet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. My only concern is for a UTF-8 sequence getting truncated.

@zdohnal
Copy link
Member Author

zdohnal commented Jan 15, 2024

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

@michaelrsweet
Copy link
Member

@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...

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 OpenPrinting#644
@zdohnal zdohnal force-pushed the job-namem-too-long branch from e1f079a to d959811 Compare January 16, 2024 07:31
@zdohnal
Copy link
Member Author

zdohnal commented Jan 16, 2024

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

@zdohnal zdohnal requested a review from michaelrsweet January 16, 2024 07:32
@jsmeix
Copy link

jsmeix commented Jan 16, 2024

@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
apple/cups#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
Copy link
Member Author

zdohnal commented Jan 16, 2024

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

@zdohnal zdohnal merged commit 881eab1 into OpenPrinting:master Jan 16, 2024
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CUPS can't print files if the job name is nearly 255 characters long
3 participants