From b55e449b9b0e3ba63b3f342eaac23aac799933bb Mon Sep 17 00:00:00 2001 From: IFAKA Date: Sat, 20 Dec 2025 19:19:31 +0100 Subject: [PATCH] fix: add NULL check after malloc in readFileToMemory() Check if output buffer allocation succeeds before using it. Follows existing pattern from deflatedData check on line 141. --- lib/ZipFile/ZipFile.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ZipFile/ZipFile.cpp b/lib/ZipFile/ZipFile.cpp index f55bb85..11ce211 100644 --- a/lib/ZipFile/ZipFile.cpp +++ b/lib/ZipFile/ZipFile.cpp @@ -118,6 +118,11 @@ uint8_t* ZipFile::readFileToMemory(const char* filename, size_t* size, const boo const auto inflatedDataSize = static_cast(fileStat.m_uncomp_size); const auto dataSize = trailingNullByte ? inflatedDataSize + 1 : inflatedDataSize; const auto data = static_cast(malloc(dataSize)); + if (data == nullptr) { + Serial.printf("[%lu] [ZIP] Failed to allocate memory for output buffer (%zu bytes)\n", millis(), dataSize); + fclose(file); + return nullptr; + } if (fileStat.m_method == MZ_NO_COMPRESSION) { // no deflation, just read content