Skip to content

Commit

Permalink
Fix off-by-one error in parsing IFWI partition table
Browse files Browse the repository at this point in the history
Fixes #376
  • Loading branch information
NikolajSchlej committed Nov 2, 2023
1 parent e0b1e02 commit 6f9a4c0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions common/meparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ USTATUS MeParser::parseIfwi16Region(const UByteArray & region, const UModelIndex
partitions.push_back(partition);
}
// Add boot partitions
for (UINT8 i = 0 ; i < 4; i++) {
for (UINT8 i = 0 ; i < 5; i++) {
if (ifwiHeader->BootPartition[i].Offset != 0 && ifwiHeader->BootPartition[i].Offset != 0xFFFFFFFF) {
IFWI_PARTITION_INFO partition = {};
partition.type = Types::IfwiPartition;
Expand Down Expand Up @@ -551,7 +551,7 @@ USTATUS MeParser::parseIfwi17Region(const UByteArray & region, const UModelIndex
partitions.push_back(partition);
}
// Add boot partitions
for (UINT8 i = 0 ; i < 4; i++) {
for (UINT8 i = 0 ; i < 5; i++) {
if (ifwiHeader->BootPartition[i].Offset != 0 && ifwiHeader->BootPartition[i].Offset != 0xFFFFFFFF) {
IFWI_PARTITION_INFO partition = {};
partition.type = Types::IfwiPartition;
Expand Down Expand Up @@ -671,8 +671,15 @@ USTATUS MeParser::parseIfwi17Region(const UByteArray & region, const UModelIndex
}
else if (partitions[i].subtype == Subtypes::BootIfwiPartition) {
// Parse code partition contents
UModelIndex bootPartitionBpdtRegionIndex;
ffsParser->parseBpdtRegion(partition, 0, 0, partitionIndex, bootPartitionBpdtRegionIndex);
UModelIndex bootPartitionRegionIndex;
if (*(UINT32*)partition.constData() == FPT_HEADER_SIGNATURE) {
// Parse as FptRegion
parseFptRegion(partition, partitionIndex, bootPartitionRegionIndex);
}
else {
// Parse as BpdtRegion
ffsParser->parseBpdtRegion(partition, 0, 0, partitionIndex, bootPartitionRegionIndex);
}
}
}
else if (partitions[i].type == Types::Padding) {
Expand Down

0 comments on commit 6f9a4c0

Please sign in to comment.