From 5554019b0b29d76e1ac069c6abf4af019c27d150 Mon Sep 17 00:00:00 2001 From: ManasBagul23 Date: Fri, 13 Nov 2026 12:38:32 +0530 Subject: [PATCH] ppd_copy_stack/ppd_index_stack: snapshot object before pushing 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. --- ppd/raster-interpret.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ppd/raster-interpret.c b/ppd/raster-interpret.c index 54b48c27..8990f7f8 100644 --- a/ppd/raster-interpret.c +++ b/ppd/raster-interpret.c @@ -885,7 +885,10 @@ ppd_copy_stack(_ppd_ps_stack_t *st, // I - Stack while (c > 0) { - if (!ppd_push_stack(st, st->objs + n)) + _ppd_ps_obj_t temp; // Temporary copy of object + + temp = st->objs[n]; + if (!ppd_push_stack(st, &temp)) return (-1); n ++; @@ -1032,10 +1035,14 @@ static _ppd_ps_obj_t * // O - New object ppd_index_stack(_ppd_ps_stack_t *st, // I - Stack int n) // I - Object index { + _ppd_ps_obj_t temp; // Temporary copy of object + + if (n < 0 || (n = st->num_objs - n - 1) < 0) return (NULL); - return (ppd_push_stack(st, st->objs + n)); + temp = st->objs[n]; + return (ppd_push_stack(st, &temp)); }