Skip to content

ppd_copy_stack/ppd_index_stack: snapshot object before pushing - #111

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix/raster-interpret-copy-stack-realloc-uaf
Nov 16, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix/raster-interpret-copy-stack-realloc-uaf

Conversation

@ManasBagul23

Copy link
Copy Markdown
Contributor

Summary

`ppd_push_stack()` can `realloc()` `st->objs` to grow the stack. Both `ppd_copy_stack()` and `ppd_index_stack()` called it with a pointer into that very array (`st->objs + n`).

The bug

If the push crosses the current `alloc_objs` boundary, `ppd_push_stack()`'s closing `memcpy()` dereferences the pointer it was handed. Since that pointer pointed into `st->objs` and `realloc()` may have moved (or in a shrink/failure case, freed) the underlying allocation by the time the `memcpy` runs, this is a read from freed/stale memory.

This is reachable whenever PPD-embedded PostScript mini-language code (`ppd->patches`, or option/JCL setup code emitted via `ppdEmitString`) executes a `copy`, `dup`, or `index` operator while `cupsRasterInterpretPPD()`/`ppdRasterExecPS()` is building the page header for an ordinary job -- a normal part of raster filtering with many manufacturer PPDs, not something exotic.

Fix

Copy the object into a local variable before calling `ppd_push_stack()`, in both `ppd_copy_stack()` and `ppd_index_stack()`. This matches upstream CUPS's own `copy_stack()`/`index_stack()`, which already do this.

Test plan

  • Confirmed both call sites still pass a raw pointer into `st->objs` on current `master`.
  • Verified `ppd_push_stack()`'s realloc path: when `st->num_objs >= st->alloc_objs`, it reallocs `st->objs` and then `memcpy`s from the caller-supplied pointer -- which, for these two callers, pointed into the array that was just reallocated.

ppd_push_stack() can realloc() st->objs to grow the stack. Both
ppd_copy_stack() and ppd_index_stack() called it with a pointer into
that very array (st->objs + n). If the push crosses the current
alloc_objs boundary, push_stack() dereferences that now-stale pointer
in its closing memcpy(), reading freed or moved memory.

This is reachable whenever PPD-embedded PostScript mini-language code
(ppd->patches or option/JCL setup code emitted via ppdEmitString)
executes a "copy", "dup", or "index" operator while
cupsRasterInterpretPPD()/ppdRasterExecPS() is building the page header
for an ordinary job, which is a normal part of raster filtering with
many manufacturer PPDs.

Upstream CUPS's copy_stack()/index_stack() avoid this by copying the
object into a local variable before calling push_stack(); restore
that here for both.
Copilot AI balanced review requested due to automatic review settings November 16, 2026 18:37

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 9cf7a3e into OpenPrinting:master Nov 16, 2026
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