Repository navigation
rastertopclx, rastertoescpx: check the row length before separating - #808
Merged
tillkamppeter merged 1 commit intoNov 19, 2026
Merged
Conversation
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.
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.
ReadLine()(dithered output) and rastertoescpxProcessLine()read each row into PixelBuffer, which iscupsBytesPerLinebytes, then passcupsWidthpixels to the libcupsfilters separation functions. Those read 1 byte per pixel for W/K, 4 for CMYK and 3 for every other color space.cupsBytesPerLineagainstcupsWidth * cupsBitsPerPixel, and for v2/v3 headerscupsNumColorscomes from the job. A raw raster job declaring CMYK withcupsNumColors1 at 8 bits gets acupsWidth-byte row whilecfCMYKDoCMYK()reads 4x that; K/W at 2 or 4 bits gets a quarter or half of whatcfCMYKDoBlack()/cfCMYKDoGray()read. The over-read heap bytes are dithered into the printer output. rastertopclx only rejects a short row forCUPS_CSPACE_RGB, but CMY, KCMY etc. take the same 3-byte path through thedefault:case, and rastertoescpx has no check at all.StartPage()of both filters whencupsBytesPerLine / bytes_per_pixel < cupsWidth, using the same color space mapping as the separation switch.Verified by building libcupsfilters'
cmyk.cwith ASan against headers that pass the CUPS 2.4cups_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 giveheap-buffer-overflow ... READ of size 1 ... 0 bytes afterthe row allocation, incfCMYKDoCMYK,cfCMYKDoBlackandcfCMYKDoRGB. 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 -Wextrawith no new diagnostics.