fix: M2 readString uint32 overflow in bounds check

offset + length was computed in uint32_t before comparing to size_t.
A crafted M2 with offset=0xFFFFFFFF, length=2 wraps to 1 in uint32,
passing the check and reading out of bounds. Now uses size_t arithmetic,
matching the readArray fix from an earlier round.
This commit is contained in:
Kelsi 2026-03-29 20:41:56 -07:00
parent fa1643dc90
commit 16aaf58198

View file

@ -364,7 +364,10 @@ std::vector<T> readArray(const std::vector<uint8_t>& data, uint32_t offset, uint
}
std::string readString(const std::vector<uint8_t>& data, uint32_t offset, uint32_t length) {
if (offset + length > data.size()) {
// Use size_t arithmetic to prevent uint32 wraparound (same fix as readArray).
// A crafted M2 with offset=0xFFFFFFFF, length=2 would wrap to 1 in uint32,
// passing the check and reading out of bounds.
if (static_cast<size_t>(offset) + static_cast<size_t>(length) > data.size()) {
return "";
}