fix BitBuffer overflow in rastertohp OutputLine deinterleave#1650
fix BitBuffer overflow in rastertohp OutputLine deinterleave#1650aizu-m wants to merge 1 commit into
Conversation
|
I'm not sure we need to worry about this with the normal users of this driver, but will investigate. Would it be possible for you to sign your commits? |
Signed-off-by: Aizal Khan <aizumusheer2@gmail.com>
5c38711 to
b189834
Compare
|
Signed off and force-pushed, so the branch now carries the DCO line. On reachability: the only way in is an untrusted application/vnd.cups-raster job to an HP PCL queue, so it's header fields a job controls rather than anything a normal user would set. An RGB or CMYK header trips it because cupsNumColors is folded into cupsBytesPerLine while NumPlanes stays 1, so count outruns the two sub-planes. Happy to attach the crafted raster if that's useful for the investigation. |
No, not needed but thanks. I meant more that nobody uses this part (HP_DESKJET2 or model 2) of the driver anymore since it was dropped in 2007... |
|
That lines up with what I traced. The overrun only sits in the multi-bit deinterleave, which is the model 2 (HP_DESKJET2) branch, so in practice it's a dead path. I'd treat the patch as cheap hardening rather than anything urgent, so fine to take it or leave it, whichever suits. |
ASan, feeding a crafted
application/vnd.cups-rasterpage to a queue that uses an HP PCL PPD:I was tracing the deep-colour (
cupsBitsPerColor > 1) branch ofOutputLine.StartPagesizesBitBufferasColorBits * (cupsWidth + 7) / 8, but the deinterleave loop runscount = cupsBytesPerLine / NumPlanestimes and writesbit_ptr[0]andbit_ptr[bytes].NumPlanesis 1 for any colourspace that is not CMY or KCMY, so an RGB or CMYK header (itscupsNumColorsalready folded intocupsBytesPerLine) makescountseveral times larger than the twobytes-wide sub-planes the buffer holds, andbit_ptr[bytes]runs past the allocation. The page above is 800px, 8-bit, RGB.Same loop, second way in:
countis unsigned and the loop only stops oncount > 0withcount -= 2, so an oddcupsBytesPerLine / NumPlanes(e.g. a 12px 2-bit black line wherecupsBytesPerLineis 3) underflows to ~2^31 and it keeps writing off the heap.Both reduce to the loop overrunning the two sub-planes, so I bounded
bit_ptrtoBitBuffer + bytes. Valid input wherecountis exactly2 * bytesreaches the bound just ascounthits 0, so nothing changes there; I diffed a 2-bit page before and after and the output is byte-identical.