From 6398dc4cc4a28c9bd6a1765d4540486799f48119 Mon Sep 17 00:00:00 2001 From: ManasBagul23 Date: Mon, 23 Nov 2026 23:36:31 +0530 Subject: [PATCH] rastertops: bound cupsBytesPerLine before sizing the line buffers write_flate() sizes its "in"/"out" stack buffers from header.cupsBytesPerLine, a field read straight off the incoming raster stream. The existing zero-guard only defaulted a zero value to 1; it did nothing for an oversized one, and worse, line_bytes and the two buffers were declared before any check ran at all, so a corrupted or malicious raster header with a huge bytes-per-line value sized an uncontrolled stack allocation before the guard even executed. Move the validation ahead of the buffer declarations and reject an unreasonably large value, not just a zero one. --- ppd/rastertops.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ppd/rastertops.c b/ppd/rastertops.c index a6de81ba..73b81677 100644 --- a/ppd/rastertops.c +++ b/ppd/rastertops.c @@ -247,13 +247,16 @@ write_flate(cups_raster_t *ras, // I - Image data // by deflate unsigned char *pixdata, *convertedpix; - size_t line_bytes = header.cupsBytesPerLine ? - (size_t)header.cupsBytesPerLine : 1; - unsigned char in[line_bytes * 6], // Input data buffer - out[line_bytes * 6]; // Output data buffer + size_t line_bytes; - if (header.cupsBytesPerLine == 0 || header.cupsHeight == 0) + if (header.cupsBytesPerLine == 0 || + header.cupsBytesPerLine > (16 * 1024 * 1024) || header.cupsHeight == 0) return (Z_DATA_ERROR); + + line_bytes = (size_t)header.cupsBytesPerLine; + + unsigned char in[line_bytes * 6], // Input data buffer + out[line_bytes * 6]; // Output data buffer // allocate deflate state strm.zalloc = Z_NULL;