mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 06:37:38 +03:00
fix: add NULL check after malloc in readFileToMemory() (#81)
## Problem `readFileToMemory()` allocates an output buffer via `malloc()` at line 120 but doesn't check if allocation succeeds. On low memory, the NULL pointer is passed to `fread()` causing a crash. ## Fix Add NULL check after `malloc()` for the output buffer. Follows the existing pattern already used for `deflatedData` at line 141. Changed `lib/ZipFile/ZipFile.cpp`. ## Test - Follows existing validated pattern from same function - Defensive addition only - no logic changes
This commit is contained in:
parent
bf3f270067
commit
cc86533e86
@ -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 dataSize = trailingNullByte ? inflatedDataSize + 1 : inflatedDataSize;
|
||||
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) {
|
||||
// no deflation, just read content
|
||||
|
||||
Loading…
Reference in New Issue
Block a user