diff options
author | Timothy Arceri <[email protected]> | 2017-08-23 16:32:58 +1000 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2017-08-25 13:20:29 +1000 |
commit | ef42423e7be93578f6896ed02e022b98323e4c8a (patch) | |
tree | 6fa93a7626442bc9497f7e0d10f84782ba49758a /src/util/disk_cache.c | |
parent | 28b326238bcc14d372880a0e4fabcece4ffdc871 (diff) |
disk_cache: enable limited hash collision detection in release builds
It really doesn't cost us much and will stop strange crashes should
the stars align.
Reviewed-by: Nicolai Hähnle <[email protected]>
Diffstat (limited to 'src/util/disk_cache.c')
-rw-r--r-- | src/util/disk_cache.c | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c index 6f467027d8e..d2cd4e85c46 100644 --- a/src/util/disk_cache.c +++ b/src/util/disk_cache.c @@ -990,6 +990,7 @@ disk_cache_get(struct disk_cache *cache, const cache_key key, size_t *size) char *filename = NULL; uint8_t *data = NULL; uint8_t *uncompressed_data = NULL; + uint8_t *file_header = NULL; if (size) *size = 0; @@ -1010,29 +1011,20 @@ disk_cache_get(struct disk_cache *cache, const cache_key key, size_t *size) goto fail; size_t ck_size = cache->driver_keys_blob_size; -#ifndef NDEBUG - uint8_t *file_header = malloc(ck_size); + file_header = malloc(ck_size); if (!file_header) goto fail; - assert(sb.st_size > ck_size); - ret = read_all(fd, file_header, ck_size); - if (ret == -1) { - free(file_header); + if (sb.st_size < ck_size) goto fail; - } - - assert(memcmp(cache->driver_keys_blob, file_header, ck_size) == 0); - free(file_header); -#else - /* The cache keys are currently just used for distributing precompiled - * shaders, they are not used by Mesa so just skip them for now. - */ - ret = lseek(fd, ck_size, SEEK_CUR); + ret = read_all(fd, file_header, ck_size); if (ret == -1) goto fail; -#endif + + /* Check for extremely unlikely hash collisions */ + if (memcmp(cache->driver_keys_blob, file_header, ck_size) != 0) + goto fail; /* Load the CRC that was created when the file was written. */ struct cache_entry_file_data cf_data; @@ -1074,6 +1066,8 @@ disk_cache_get(struct disk_cache *cache, const cache_key key, size_t *size) free(uncompressed_data); if (filename) free(filename); + if (file_header) + free(file_header); if (fd != -1) close(fd); |