From e327966a50ab1334ba6641c692528e2c2ef4aa46 Mon Sep 17 00:00:00 2001 From: mkilijanek Date: Tue, 20 Oct 2026 19:55:14 +0200 Subject: [PATCH] [BUGFIX] AbstractByteBuffer::getContentAt: catch the wrap of offset + size getContentAt checked the requested area as `offset + size > fileSize`. With a size close to 2^64 the sum wraps to a small value, the check passes, and a pointer is returned for an area that is almost entirely outside the buffer. Such sizes come from unsigned underflows of PE-supplied fields, for example a value computed as `dwLength - 10`. Compare the size with what is left after the offset instead (size > fileSize - offset; offset < fileSize is already checked above). On a 0x100-byte ByteBuffer: getContentAt(0x10, -8) returned a non-NULL pointer before and returns NULL now; getContentAt(0x10, 0xf0) is still accepted and (0x10, 0xf1) is still rejected. --- parser/AbstractByteBuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser/AbstractByteBuffer.cpp b/parser/AbstractByteBuffer.cpp index c4bd2614..de9573a1 100644 --- a/parser/AbstractByteBuffer.cpp +++ b/parser/AbstractByteBuffer.cpp @@ -75,7 +75,7 @@ BYTE* AbstractByteBuffer::getContentAt(offset_t offset, bufsize_t size, bool all return NULL; } const offset_t endOffset = offset + size; - if (endOffset > fileSize) { + if (size > fileSize - offset) { // offset < fileSize: no underflow; offset + size may wrap if (allowExceptions) throw BufferException("Too big size requested! Buffer size: " + QString::number(fileSize) + " vs end of the requested area: 0x" + QString::number(endOffset, 16)); return NULL;