Skip to content

pdftops: reject a negative pdftops-max-image-resolution - #121

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix/pdftops-negative-max-image-resolution-hang-pr
Nov 22, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix/pdftops-negative-max-image-resolution-hang-pr

Conversation

@ManasBagul23

Copy link
Copy Markdown
Contributor

The pdftops-max-image-resolution job option is parsed with sscanf("%d") and stored into mres/maxres without any range check. The resolution ceiling is then applied with:

if (maxres)
  while (res > maxres)
    res = res / 2;

For a negative maxres, res halves down to 0 (integer division) and stays there, and 0 > maxres remains true forever since maxres is negative — the loop never terminates. A job submitted with e.g. -o pdftops-max-image-resolution=-1 hangs ppdFilterPDFToPS() at 100% CPU before the renderer is even started.

Only accept non-negative values from sscanf; a negative or unparsable value now falls through to the existing "Invalid value" warning and keeps the default ceiling, matching how every other invalid input to this option is already handled.

The "pdftops-max-image-resolution" job option is parsed with
sscanf("%d") and stored into maxres without a range check. The image
rendering resolution is then reduced with

  if (maxres)
    while (res > maxres)
      res = res / 2;

For a negative value, res halves down to 0 and then stays there, and
0 > maxres is still true, so the loop never terminates: a job submitted
with e.g. -o pdftops-max-image-resolution=-1 hangs ppdFilterPDFToPS()
at 100% CPU before the renderer is ever started.

Only accept non-negative values; anything else falls through to the
existing "Invalid value" warning and keeps the default ceiling.
Copilot AI balanced review requested due to automatic review settings November 22, 2026 18:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@tillkamppeter
tillkamppeter merged commit 16d2ebd into OpenPrinting:master Nov 22, 2026
14 of 15 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.

3 participants