1
0
mirror of https://github.com/upx/upx synced 2025-10-05 19:20:23 +08:00

src: add some bounds checking to MemBufferBase

This commit is contained in:
Markus F.X.J. Oberhumer 2024-01-31 16:48:55 +01:00
parent c0e40da2ab
commit d849e9de98

View File

@ -55,6 +55,17 @@ public:
// HINT: for fully bound-checked pointer use XSPAN_S from xspan.h
operator pointer() const noexcept { return ptr; }
// array access
reference operator[](ptrdiff_t i) const may_throw {
if very_unlikely (i < 0 || mem_size(sizeof(element_type), i) >= size_in_bytes)
throwCantPack("MemBuffer invalid index %td (%u bytes)", i, size_in_bytes);
return ptr[i];
}
// dereference
reference operator*() const DELETED_FUNCTION;
// arrow operator
pointer operator->() const DELETED_FUNCTION;
// membuffer + n -> pointer
template <class U>
typename std::enable_if<std::is_integral<U>::value, pointer>::type operator+(U n) const {