From cca2f79dfeb492926bd41619bd2ef931f77d00da Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 9 Nov 2020 14:45:57 -0800 Subject: load_cache: treat invalid frame header as EOF In preparation for posix_fallocate() pre-allocation of cache files, expect zeroes for the header when running off the end of valid data into the only allocated space, and handle gracefully as an EOF equivalent. --- src/rmd_load_cache.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rmd_load_cache.c b/src/rmd_load_cache.c index 4ad1741..303cc3b 100644 --- a/src/rmd_load_cache.c +++ b/src/rmd_load_cache.c @@ -153,7 +153,10 @@ static int rmdReadFrame(CachedFrame *frame, CacheFile *icf) static int read_header(FrameHeader *fheader, CacheFile *icf) { - return rmdCacheFileRead(icf, fheader, sizeof(FrameHeader)) == sizeof(FrameHeader); + if (!(rmdCacheFileRead(icf, fheader, sizeof(FrameHeader)) == sizeof(FrameHeader))) + return 0; + + return !strncmp(fheader->frame_prefix, "FRAM", 4); } void *rmdLoadCache(ProgData *pdata) -- cgit v1.2.3