The code first checks to see if the buffer size is larger than the max allowed size. It then proceeds to erase from the beginning of the buffer to an offset, calculated by subtracting the larger, old buffer size from the smaller, new buffer size. As this is done with STL iterators, the operation is not quite defined, and the behavior while attempting to erase from the beginning of the vector to an iterator which points to a element before the beginning of the vector is most likely causing a segmentation fault.
To fix, one could simply reverse the order of operands in the subtraction. Trimming the first (oldlen - newlen) elements will result in an accurate new buffer size.
There is faulty code in the new TrimBuffer method invoked when the buffer size is shunk.
On lines 535-537:
```
if (m_vsBuffer.size() > uMax) {
m_vsBuffer.erase(m_vsBuffer.begin(), m_vsBuffer.begin() + (uMax - m_vsBuffer.size()));
}
```
The code first checks to see if the buffer size is larger than the max allowed size. It then proceeds to erase from the beginning of the buffer to an offset, calculated by subtracting the **larger, old buffer size** from the smaller, new buffer size. As this is done with STL iterators, the operation is not quite defined, and the behavior while attempting to erase from the beginning of the vector to an iterator which points to a element _before_ the beginning of the vector is most likely causing a segmentation fault.
To fix, one could simply reverse the order of operands in the subtraction. Trimming the first (oldlen - newlen) elements will result in an accurate new buffer size.
---
Introduced in: f6113b322dbb32af6b27b72e3a557e46acf20ffb
<!-- github-sync-id:1475391 -->
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
There is faulty code in the new TrimBuffer method invoked when the buffer size is shunk.
On lines 535-537:
The code first checks to see if the buffer size is larger than the max allowed size. It then proceeds to erase from the beginning of the buffer to an offset, calculated by subtracting the larger, old buffer size from the smaller, new buffer size. As this is done with STL iterators, the operation is not quite defined, and the behavior while attempting to erase from the beginning of the vector to an iterator which points to a element before the beginning of the vector is most likely causing a segmentation fault.
To fix, one could simply reverse the order of operands in the subtraction. Trimming the first (oldlen - newlen) elements will result in an accurate new buffer size.
Introduced in:
f6113b322d