mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-11 13:30:47 -04:00
Check against overflow due to corrupted length field
This commit is contained in:
parent
dff559bc3f
commit
3cf157421d
@ -98,11 +98,18 @@ class filesystem_parser {
|
||||
auto sh = mm.as<section_header_v2>(pos);
|
||||
|
||||
if (sh->number == 0) {
|
||||
if (pos + 2 * sizeof(section_header_v2) + sh->length >= mm.size()) {
|
||||
auto endpos = pos + sh->length + 2 * sizeof(section_header_v2);
|
||||
|
||||
if (endpos < sh->length) {
|
||||
// overflow
|
||||
break;
|
||||
}
|
||||
|
||||
ps = mm.as<void>(pos + sizeof(section_header_v2) + sh->length);
|
||||
if (endpos >= mm.size()) {
|
||||
break;
|
||||
}
|
||||
|
||||
ps = mm.as<void>(pos + sh->length + sizeof(section_header_v2));
|
||||
|
||||
if (::memcmp(ps, magic.data(), magic.size()) == 0 and
|
||||
reinterpret_cast<section_header_v2 const*>(ps)->number == 1) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user