防止内存越界

This commit is contained in:
ziyue 2022-07-18 15:41:18 +08:00
parent d703ec29c6
commit b19574cea7

View File

@ -480,10 +480,10 @@ double AMFDecoder::load<double>() {
if (pos + 8 > buf.size()) { if (pos + 8 > buf.size()) {
throw std::runtime_error("Not enough data"); throw std::runtime_error("Not enough data");
} }
uint64_t val = ((uint64_t) load_be32(&buf[pos]) << 32) uint64_t val = ((uint64_t) load_be32(&buf[pos]) << 32) | load_be32(&buf[pos + 4]);
| load_be32(&buf[pos + 4]);
double n = 0; double n = 0;
memcpy(&n, &val, 8); static_assert(sizeof(n) == sizeof(val), "sizeof(double) not eq sizeof(uint64_t)");
memcpy(&n, &val, sizeof(n));
pos += 8; pos += 8;
return n; return n;