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:
parent
cfe838e03b
commit
b55e449b9b
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user