From bf3adbe4c6e1e420728e6f0c9b533900b185f83a Mon Sep 17 00:00:00 2001 From: vit9696 Date: Fri, 24 Jan 2020 22:36:39 +0300 Subject: [PATCH] Fix infinite loop due to 0-sized volume files closes #191 --- common/ffsparser.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/ffsparser.cpp b/common/ffsparser.cpp index c744fb7..48445d0 100644 --- a/common/ffsparser.cpp +++ b/common/ffsparser.cpp @@ -1467,6 +1467,11 @@ USTATUS FfsParser::parseVolumeBody(const UModelIndex & index) while (fileOffset < volumeBodySize) { UINT32 fileSize = getFileSize(volumeBody, fileOffset, ffsVersion); + if (fileSize == 0) { + msg(usprintf("%s: file header parsing failed with invalid size", __FUNCTION__), index); + return U_INVALID_PARAMETER; + } + // Check that we are at the empty space UByteArray header = volumeBody.mid(fileOffset, (int)std::min(sizeof(EFI_FFS_FILE_HEADER), (size_t)volumeBodySize - fileOffset)); if (header.count(emptyByte) == header.size()) { //Empty space