mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-06-03 21:53:48 -04:00
fix: getRemainingSize() underflowed when readPos exceeded data size
Both operands are size_t (unsigned), so if readPos > data.size() the subtraction wrapped to ~0 instead of returning 0. This could happen via setReadPos() which has no bounds check. Downstream hasRemaining() was already safe but getRemainingSize() callers (e.g. hasFullPackedGuid) would see billions of bytes available.
This commit is contained in:
@@ -35,7 +35,9 @@ public:
|
||||
const std::vector<uint8_t>& getData() const { return data; }
|
||||
size_t getReadPos() const { return readPos; }
|
||||
size_t getSize() const { return data.size(); }
|
||||
size_t getRemainingSize() const { return data.size() - readPos; }
|
||||
// Clamp to 0 instead of wrapping to ~(size_t)0 when readPos overshoots
|
||||
// (can happen via setReadPos with an unchecked offset).
|
||||
size_t getRemainingSize() const { return (readPos <= data.size()) ? (data.size() - readPos) : 0; }
|
||||
bool hasRemaining(size_t need) const { return readPos <= data.size() && need <= (data.size() - readPos); }
|
||||
bool hasFullPackedGuid() const {
|
||||
if (readPos >= data.size()) return false;
|
||||
|
||||
Reference in New Issue
Block a user