mirror of
https://github.com/cdcseacave/TinyEXIF.git
synced 2026-07-21 19:23:01 +04:00
Fix possible integer overflow in parseString bounds check (#26)
* Fix integer overflow in parseString bounds check Cast `base` to `uint64_t` in the parseString bounds check `base+data+num_components <= len` to prevent unsigned integer overflow. When `data` is attacker-controlled (e.g. 0xffffffff), the 32-bit unsigned addition wraps around, causing the check to pass even though the computed offset is far beyond the buffer. This leads to an out-of-bounds heap read or segfault when dereferencing the resulting pointer. Fixes #16 * Fix type casting for base pointer comparison
This commit is contained in:
+1
-1
@@ -301,7 +301,7 @@ public:
|
|||||||
if (value[num_components-1] == '\0')
|
if (value[num_components-1] == '\0')
|
||||||
value.resize(num_components-1);
|
value.resize(num_components-1);
|
||||||
} else
|
} else
|
||||||
if (base+data+num_components <= len) {
|
if ((uint64_t)base+data+num_components <= (uint64_t)len) {
|
||||||
const char* const sz((const char*)buf+base+data);
|
const char* const sz((const char*)buf+base+data);
|
||||||
unsigned num(0);
|
unsigned num(0);
|
||||||
while (num < num_components && sz[num] != '\0')
|
while (num < num_components && sz[num] != '\0')
|
||||||
|
|||||||
Reference in New Issue
Block a user