mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
Validate file handle when reading progress.bin (#66)
## Problem Reading progress.bin used `SD.exists()` then `SD.open()` without checking if open succeeded. Race conditions or SD errors could cause file handle to be invalid. ## Fix - Removed redundant `SD.exists()` check - Check if file opened successfully before reading - Verify correct number of bytes were read ## Testing - Builds successfully with `pio run` - Affects: `src/activities/reader/EpubReaderActivity.cpp`
This commit is contained in:
parent
48249fbd1e
commit
2d3928ed81
@ -33,13 +33,14 @@ void EpubReaderActivity::onEnter() {
|
||||
|
||||
epub->setupCacheDir();
|
||||
|
||||
if (SD.exists((epub->getCachePath() + "/progress.bin").c_str())) {
|
||||
File f = SD.open((epub->getCachePath() + "/progress.bin").c_str());
|
||||
if (f) {
|
||||
uint8_t data[4];
|
||||
f.read(data, 4);
|
||||
if (f.read(data, 4) == 4) {
|
||||
currentSpineIndex = data[0] + (data[1] << 8);
|
||||
nextPageNumber = data[2] + (data[3] << 8);
|
||||
Serial.printf("[%lu] [ERS] Loaded cache: %d, %d\n", millis(), currentSpineIndex, nextPageNumber);
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user