Skip to content

Commit fa9032a

Browse files
Nick Summeta-codesync[bot]
authored andcommitted
Revert D116335797
Summary: This diff reverts D116335797 ("[folly] fix integer overflow in `IOBuf::coalesceAndReallocate`"). `IOBuf::coalesceAndReallocate` goes back to computing `newCapacity = newLength + newHeadroom + newTailroom` with unchecked `size_t` addition, and the `TEST(IOBuf, CoalesceCapacityOverflow)` regression test is removed. S698837 Reviewed By: ericcfu Differential Revision: D116862638 fbshipit-source-id: 0723175e22b0b6b1ce424469175bae5b180bbe32
1 parent 514cda3 commit fa9032a

2 files changed

Lines changed: 1 addition & 18 deletions

File tree

third-party/folly/src/folly/io/IOBuf.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,11 +1044,7 @@ void IOBuf::coalesceSlow(size_t maxLength) {
10441044

10451045
void IOBuf::coalesceAndReallocate(
10461046
size_t newHeadroom, size_t newLength, IOBuf* end, size_t newTailroom) {
1047-
std::size_t newCapacity = 0;
1048-
if (!checked_add(&newCapacity, newLength, newHeadroom, newTailroom) ||
1049-
newCapacity > kMaxIOBufSize) {
1050-
throw_exception<std::bad_alloc>();
1051-
}
1047+
std::size_t newCapacity = newLength + newHeadroom + newTailroom;
10521048

10531049
// Allocate space for the coalesced buffer.
10541050
// We always convert to an external buffer, even if we happened to be an

third-party/folly/src/folly/io/test/IOBufTest.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,19 +1576,6 @@ TEST(IOBuf, CoalesceEmptyBuffers) {
15761576
EXPECT_TRUE(ByteRange(StringPiece("hello")) == br);
15771577
}
15781578

1579-
// A chain whose coalesced capacity (length + newHeadroom + newTailroom)
1580-
// overflows size_t must throw std::bad_alloc rather than wrapping around to a
1581-
// small capacity, allocating an undersized buffer, and overflowing it while
1582-
// copying the data.
1583-
TEST(IOBuf, CoalesceCapacityOverflow) {
1584-
auto head = fromStr("hello");
1585-
head->insertAfterThisOne(fromStr("world"));
1586-
ASSERT_TRUE(head->isChained());
1587-
1588-
constexpr auto kMax = std::numeric_limits<std::size_t>::max();
1589-
EXPECT_THROW(head->coalesceWithHeadroomTailroom(kMax, kMax), std::bad_alloc);
1590-
}
1591-
15921579
// cloneCoalescedAsValueWithHeadroomTailroom (and the unique_ptr wrapper that
15931580
// forwards to it) must throw std::bad_alloc when the coalesced capacity
15941581
// overflows size_t rather than wrapping around to an undersized buffer.

0 commit comments

Comments
 (0)