Skip to content

Limit nested IPP data-file collection parsing - #222

Open
ManasBagul23 wants to merge 2 commits into
OpenPrinting:masterfrom
ManasBagul23:fix/ippfile-nested-collection-limit-pr
Open

ManasBagul23 wants to merge 2 commits into
OpenPrinting:masterfrom
ManasBagul23:fix/ippfile-nested-collection-limit-pr

Conversation

@ManasBagul23

Copy link
Copy Markdown
Contributor

ippFileReadCollection and parse_value recurse for each nested collection without a depth limit. A deeply nested IPP data file can exhaust the process stack. Track collection nesting on the file object and reject input once it exceeds a fixed maximum depth.

ippFileReadCollection() and parse_value() call each other recursively
once per nested collection value ("{ ... }" inside an ATTR/MEMBER), with
no limit on how deep that nesting can go. A data/test file with enough
nested collection values drives this straight into a stack overflow
instead of a parse error. Track the current nesting depth on the file
object and refuse to go past a reasonable limit.

@michaelrsweet michaelrsweet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the max depth should be common between the IPP message parser (max depth 10) and IPP files...

@michaelrsweet michaelrsweet self-assigned this Nov 19, 2026
@michaelrsweet michaelrsweet added the enhancement New feature or request label Nov 19, 2026
@michaelrsweet michaelrsweet added this to the Stable milestone Nov 19, 2026
@ManasBagul23

Copy link
Copy Markdown
Contributor Author

Agreed. I moved the limit into the shared private header and now use it in both the IPP message parser and IPP data-file collection parser, keeping the maximum depth at 10.

@michaelrsweet michaelrsweet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm liking the changes, just need a little cleanup (see comments) and we should be good. Thanks!

Comment thread cups/cups-private.h
//

# define _CUPS_MAX_OPTION_DEPTH 4 // Maximum depth of nested options/collections
# define _IPP_MAX_DEPTH 10 // Maximum depth of nested IPP collections

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be in ipp-private.h...

Comment thread cups/ipp-file.c
void *cb_data; // Callback data
char *buffer; // Output buffer
size_t alloc_buffer; // Size of output buffer
size_t collection_depth;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can just be an int...

Comment thread cups/ipp-file.c
};


//

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and probably remove this comment block... :)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants