Repository navigation
ppd_copy_stack/ppd_index_stack: snapshot object before pushing - #111
Merged
tillkamppeter merged 1 commit intoNov 16, 2026
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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