Skip to content

rastertopclx, rastertoescpx: check the row length before separating - #808

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
Sharadhi-v98:raster-separation-row-length
Nov 19, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
Sharadhi-v98:raster-separation-row-length

Conversation

@Sharadhi-v98

Copy link
Copy Markdown
Contributor
  1. rastertopclx ReadLine() (dithered output) and rastertoescpx ProcessLine() read each row into PixelBuffer, which is cupsBytesPerLine bytes, then pass cupsWidth pixels to the libcupsfilters separation functions. Those read 1 byte per pixel for W/K, 4 for CMYK and 3 for every other color space.
  2. The CUPS 2.4 raster reader only checks cupsBytesPerLine against cupsWidth * cupsBitsPerPixel, and for v2/v3 headers cupsNumColors comes from the job. A raw raster job declaring CMYK with cupsNumColors 1 at 8 bits gets a cupsWidth-byte row while cfCMYKDoCMYK() reads 4x that; K/W at 2 or 4 bits gets a quarter or half of what cfCMYKDoBlack()/cfCMYKDoGray() read. The over-read heap bytes are dithered into the printer output. rastertopclx only rejects a short row for CUPS_CSPACE_RGB, but CMY, KCMY etc. take the same 3-byte path through the default: case, and rastertoescpx has no check at all.
  3. Reject the page in StartPage() of both filters when cupsBytesPerLine / bytes_per_pixel < cupsWidth, using the same color space mapping as the separation switch.

Verified by building libcupsfilters' cmyk.c with ASan against headers that pass the CUPS 2.4 cups_raster_update() validation: CMYK/1-color/8-bit, K/2-bit, RGB/1-color/8-bit (escpx) and CMY/1-color/8-bit (pclx) all give heap-buffer-overflow ... READ of size 1 ... 0 bytes after the row allocation, in cfCMYKDoCMYK, cfCMYKDoBlack and cfCMYKDoRGB. All four are rejected by the new check, while normal 8-bit K/CMYK/RGB and 16-bit W pages still pass. Both files compile with -Wall -Wextra with no new diagnostics.

rastertopclx ReadLine() (dithered output) and rastertoescpx ProcessLine()
read each row into PixelBuffer, which is cupsBytesPerLine bytes long, and
then hand cupsWidth pixels to the libcupsfilters separation functions.
Those read 1 byte per pixel for W/K, 4 for CMYK and 3 for every other
color space.

The CUPS raster reader only checks cupsBytesPerLine against cupsWidth *
cupsBitsPerPixel, and for v2/v3 headers cupsNumColors comes from the
job. So a raster that declares CMYK with cupsNumColors 1 at 8 bits gets
a row of cupsWidth bytes while cfCMYKDoCMYK() reads 4 * cupsWidth, and
K/W at 2 or 4 bits gets a quarter or half of what cfCMYKDoBlack() and
cfCMYKDoGray() read. The bytes read past the row are dithered into the
printer output.

rastertopclx only rejects a short row for CUPS_CSPACE_RGB, although CMY,
KCMY and the other color spaces go through the same 3-byte RGB path in
the default case. rastertoescpx has no check at all.

Reject the page in StartPage() of both filters when cupsBytesPerLine is
too short for cupsWidth pixels in the color space the separation will
use.
@tillkamppeter
tillkamppeter merged commit c5063e3 into OpenPrinting:master Nov 19, 2026
10 of 11 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.

2 participants