Skip to content

Commit ea35fb2

Browse files
pagabucNikolajSchlej
authored andcommitted
fix a few off-by-one errors
1 parent 786032d commit ea35fb2

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

common/ffsparser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5057,7 +5057,7 @@ USTATUS FfsParser::parseCpdRegion(const UByteArray & region, const UINT32 localO
50575057
// Parse into data block, find Module Attributes extension, and get compressed size from there
50585058
UINT32 offset = 0;
50595059
UINT32 length = 0xFFFFFFFF; // Special guardian value
5060-
if(region.size() < partitions[i].ptEntry.Offset.Offset)
5060+
if(region.size() <= partitions[i].ptEntry.Offset.Offset)
50615061
break;
50625062
UByteArray partition = region.mid(partitions[i].ptEntry.Offset.Offset, partitions[i].ptEntry.Length);
50635063
while (offset < ((UINT32)partition.size() - sizeof(CPD_EXTENTION_HEADER))) {

common/meparser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ USTATUS MeParser::parseFptRegion(const UByteArray & region, const UModelIndex &
184184
UINT32 numEntries = ptHeader->NumEntries;
185185
const FPT_HEADER_ENTRY* firstPtEntry = (const FPT_HEADER_ENTRY*)(region.constData() + offset);
186186

187-
if ((UINT32)offset + sizeof(const FPT_HEADER_ENTRY*) * numEntries > region.size()) {
187+
if ((UINT32)offset + sizeof(FPT_HEADER_ENTRY) * numEntries >= region.size()) {
188188
msg(usprintf("%s: Corrupted ME region, too many header entries", __FUNCTION__), parent);
189189
return U_INVALID_ME_PARTITION_TABLE;
190190
}
@@ -467,7 +467,7 @@ USTATUS MeParser::parseIfwi16Region(const UByteArray & region, const UModelIndex
467467
// Partition map is consistent
468468
for (size_t i = 0; i < partitions.size(); i++) {
469469
// Sanity check
470-
if (partitions[i].ptEntry.Offset > region.size())
470+
if (partitions[i].ptEntry.Offset >= region.size())
471471
break;
472472
UByteArray partition = region.mid(partitions[i].ptEntry.Offset, partitions[i].ptEntry.Size);
473473
if (partitions[i].type == Types::IfwiPartition) {

0 commit comments

Comments
 (0)