fix heap overflow in ppdEmitString custom value buffer sizing - #1656
fix heap overflow in ppdEmitString custom value buffer sizing#1656aizu-m wants to merge 1 commit into
Conversation
Signed-off-by: Aizal Khan <aizumusheer2@gmail.com>
michaelrsweet
left a comment
There was a problem hiding this comment.
There is a difference between real values that will be used for printing (with much much smaller limits on the supported values) vs. synthetic test values you use to try to break things.
Seems like the proper solution here is to set an upper limit of characters per number and then use that vs. using wildly inflated memory reservation that has its own issues (i.e. OOM crashes).
|
I pushed an alternate fix that limits each number to [master 00eef0e] Better limit the size of custom numbers in PS option output (Issue #1656) [2.4.x b125eff] Better limit the size of custom numbers in PS option output (Issue #1656) |
ASan, printing with
-o PageSize=Custom.340282346638528859811704183484516925440x340282346638528859811704183484516925440:Came out of reading the sizing loop next to the emit loop. Sizing reserves 10 bytes per custom number and 50 for the five CustomPageSize numbers. Emission goes through
_cupsStrFormatd, which formats%.12f, so a float takes up to 39 integer digits, 53 characters with sign and fraction. Nothing clamps the value first:ppdPageSizereads Custom.WIDTHxLENGTH straight out of the job option without checking custom_min/custom_max, andppd_mark_optionstores custom real/points/int parameters the same way.Past the reservation bufptr runs beyond bufend, and the writes after the numbers carry no bound: the newline after each number, the memcpy of the choice code at :1070, and the
(size_t)(bufend - bufptr + 1)length at :1077 that underflows to SIZE_MAX. A custom option with three real parameters is worse:The JCL branch undercounts the same way, but its emit loop is bounded, so there it only truncates. All three reservations now use the real
%.12fwidth. No behaviour change for in-range values; the new testppd case fails on master and passes here.