fix BitBuffer overflow in rastertohp OutputLine deinterleave#1650
Open
aizu-m wants to merge 1 commit into
Open
fix BitBuffer overflow in rastertohp OutputLine deinterleave#1650aizu-m wants to merge 1 commit into
aizu-m wants to merge 1 commit into
Conversation
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.
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.