Avoid underflow when using TestDisk on file smaller than 512 bytes

This commit is contained in:
Christophe Grenier 2012-12-23 17:08:55 +01:00
parent 2f15003805
commit b4a555b8a5
2 changed files with 19 additions and 5 deletions

View file

@ -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;
}

View file

@ -249,10 +249,13 @@ static list_part_t *read_part_none(disk_t *disk, const int verbose, const int sa
}
if(res<=0)
{ /* Search NTFS backup */
partition->part_offset = disk->disk_size - disk->sector_size;
res=search_NTFS_backup(buffer_disk, disk, partition, verbose, 0);
if(res>0 && partition->part_offset!=0)
res=0;
if(disk->disk_size > disk->sector_size)
{
partition->part_offset = disk->disk_size - disk->sector_size;
res=search_NTFS_backup(buffer_disk, disk, partition, verbose, 0);
if(res>0 && partition->part_offset!=0)
res=0;
}
}
if(res<=0)
{