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.
This commit is contained in:
IFAKA 2025-12-20 19:19:31 +01:00
parent cfe838e03b
commit b55e449b9b

View File

@ -118,6 +118,11 @@ uint8_t* ZipFile::readFileToMemory(const char* filename, size_t* size, const boo
const auto inflatedDataSize = static_cast<size_t>(fileStat.m_uncomp_size); const auto inflatedDataSize = static_cast<size_t>(fileStat.m_uncomp_size);
const auto dataSize = trailingNullByte ? inflatedDataSize + 1 : inflatedDataSize; const auto dataSize = trailingNullByte ? inflatedDataSize + 1 : inflatedDataSize;
const auto data = static_cast<uint8_t*>(malloc(dataSize)); const auto data = static_cast<uint8_t*>(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) { if (fileStat.m_method == MZ_NO_COMPRESSION) {
// no deflation, just read content // no deflation, just read content