Commit 51b3a7f
fix integer overflow in IOBuf::cloneCoalescedAsValueWithHeadroomTailroom
Summary:
Follow-up to D116335797, which fixed the integer-overflow → heap-buffer-overflow in `IOBuf::coalesceAndReallocate`. The sibling path `cloneCoalescedAsValueWithHeadroomTailroom` re-implements the same unchecked three-term sum `newLength + newHeadroom + newTailroom`, which wraps when attacker-controlled `headroom`/`tailroom` are forwarded through the public `cloneCoalesced*WithHeadroomTailroom` APIs, under-allocating the buffer and overflowing it while copying.
This guards the "Coalesce into newBuf" capacity with `checked_add` + `kMaxIOBufSize`, throwing `std::bad_alloc` on overflow — mirroring the existing idiom in `coalesceAndReallocate`. The unique_ptr wrapper forwards to the by-value overload, so both public entry points are covered. This re-applies the `clone` hunk from the reverted D115286348 while leaving the already-landed `coalesceAndReallocate` guard untouched.
Reviewed By: ilvokhin
Differential Revision: D116669664
fbshipit-source-id: 14f433f1793ad102ef97e66a7ac52d62ca5bb5a31 parent 25062c6 commit 51b3a7f
2 files changed
Lines changed: 21 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
860 | 860 | | |
861 | 861 | | |
862 | 862 | | |
863 | | - | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
864 | 868 | | |
865 | 869 | | |
866 | 870 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1589 | 1589 | | |
1590 | 1590 | | |
1591 | 1591 | | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
1592 | 1608 | | |
1593 | 1609 | | |
1594 | 1610 | | |
| |||
0 commit comments