mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-03 20:03:50 +00: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:
parent
9da97e5e88
commit
ed63b029cd
1 changed files with 3 additions and 1 deletions
|
|
@ -35,7 +35,9 @@ public:
|
||||||
const std::vector<uint8_t>& getData() const { return data; }
|
const std::vector<uint8_t>& getData() const { return data; }
|
||||||
size_t getReadPos() const { return readPos; }
|
size_t getReadPos() const { return readPos; }
|
||||||
size_t getSize() const { return data.size(); }
|
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 hasRemaining(size_t need) const { return readPos <= data.size() && need <= (data.size() - readPos); }
|
||||||
bool hasFullPackedGuid() const {
|
bool hasFullPackedGuid() const {
|
||||||
if (readPos >= data.size()) return false;
|
if (readPos >= data.size()) return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue