summaryrefslogtreecommitdiffstats
path: root/src/hdcache.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2012-12-23 17:08:55 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2012-12-23 17:08:55 +0100
commitb4a555b8a56d97b633623241199b23f9816e54fa (patch)
treee2c75c74a95886342186c5f1c45c4c0d17a0681a /src/hdcache.c
parent2f1500380561425cbcfbd648ad07ff1703162178 (diff)
Avoid underflow when using TestDisk on file smaller than 512 bytes
Diffstat (limited to 'src/hdcache.c')
-rw-r--r--src/hdcache.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/hdcache.c b/src/hdcache.c
index 9ace3d7..f2eadb8 100644
--- a/src/hdcache.c
+++ b/src/hdcache.c
@@ -83,8 +83,19 @@ static void *cache_get_data_p(disk_t *disk, const unsigned int count, const uint
const struct cache_buffer_struct *cache=&data->cache[cache_buffer_nbr];
if(cache->buffer!=NULL && cache->cache_size>0 &&
cache->cache_offset <= offset &&
- offset + count < cache->cache_offset + cache->cache_size)
+ offset + count < cache->cache_offset + cache->cache_size &&
+ offset + count >= offset)
+ {
+#ifdef DEBUG_CACHE
+ log_info("cache_get_data_p(buffer, count=%u, offset=%llu)\n",
+ count, (long long unsigned)offset);
+ log_info("cache use %5u count=%u, coffset=%llu, cstatus=%d\n",
+ cache_buffer_nbr, cache->cache_size, (long long unsigned)cache->cache_offset,
+ cache->cache_status);
+ data->nbr_fnct_sect+=count;
+#endif
return cache->buffer + offset - cache->cache_offset;
+ }
}
return NULL;
}