From 6875968d97d0b37779c49e30a53d9f837500a417 Mon Sep 17 00:00:00 2001 From: yeggor Date: Fri, 17 Mar 2023 02:10:32 +0400 Subject: [PATCH] Check partitions size before erasing to avoid memory corruption --- common/ffsparser.cpp | 6 ++++++ common/meparser.cpp | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/common/ffsparser.cpp b/common/ffsparser.cpp index 6701926..9d48b6f 100644 --- a/common/ffsparser.cpp +++ b/common/ffsparser.cpp @@ -4220,6 +4220,9 @@ USTATUS FfsParser::parseBpdtRegion(const UByteArray & region, const UINT32 local } make_partition_table_consistent: + if (partitions.empty()) { + return U_INVALID_ME_PARTITION_TABLE; + } // Sort partitions by offset std::sort(partitions.begin(), partitions.end()); @@ -4521,6 +4524,9 @@ USTATUS FfsParser::parseCpdRegion(const UByteArray & region, const UINT32 localO } make_partition_table_consistent: + if (partitions.empty()) { + return U_INVALID_ME_PARTITION_TABLE; + } // Sort partitions by offset std::sort(partitions.begin(), partitions.end()); diff --git a/common/meparser.cpp b/common/meparser.cpp index e4d2280..0309406 100755 --- a/common/meparser.cpp +++ b/common/meparser.cpp @@ -223,7 +223,9 @@ USTATUS MeParser::parseFptRegion(const UByteArray & region, const UModelIndex & } make_partition_table_consistent: - + if (partitions.empty()) { + return U_INVALID_ME_PARTITION_TABLE; + } // Sort partitions by offset std::sort(partitions.begin(), partitions.end()); @@ -384,6 +386,9 @@ USTATUS MeParser::parseIfwi16Region(const UByteArray & region, const UModelIndex } make_partition_table_consistent: + if (partitions.empty()) { + return U_INVALID_ME_PARTITION_TABLE; + } // Sort partitions by offset std::sort(partitions.begin(), partitions.end()); @@ -565,6 +570,9 @@ USTATUS MeParser::parseIfwi17Region(const UByteArray & region, const UModelIndex } make_partition_table_consistent: + if (partitions.empty()) { + return U_INVALID_ME_PARTITION_TABLE; + } // Sort partitions by offset std::sort(partitions.begin(), partitions.end());