mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-04-21 01:10:44 +02:00
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 <nicolai.haehnle@amd.com>
This commit is contained in:
parent
28b326238b
commit
ef42423e7b
1 changed files with 10 additions and 16 deletions
|
|
@ -990,6 +990,7 @@ disk_cache_get(struct disk_cache *cache, const cache_key key, size_t *size)
|
||||||
char *filename = NULL;
|
char *filename = NULL;
|
||||||
uint8_t *data = NULL;
|
uint8_t *data = NULL;
|
||||||
uint8_t *uncompressed_data = NULL;
|
uint8_t *uncompressed_data = NULL;
|
||||||
|
uint8_t *file_header = NULL;
|
||||||
|
|
||||||
if (size)
|
if (size)
|
||||||
*size = 0;
|
*size = 0;
|
||||||
|
|
@ -1010,29 +1011,20 @@ disk_cache_get(struct disk_cache *cache, const cache_key key, size_t *size)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
size_t ck_size = cache->driver_keys_blob_size;
|
size_t ck_size = cache->driver_keys_blob_size;
|
||||||
#ifndef NDEBUG
|
file_header = malloc(ck_size);
|
||||||
uint8_t *file_header = malloc(ck_size);
|
|
||||||
if (!file_header)
|
if (!file_header)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
assert(sb.st_size > ck_size);
|
if (sb.st_size < ck_size)
|
||||||
ret = read_all(fd, file_header, ck_size);
|
|
||||||
if (ret == -1) {
|
|
||||||
free(file_header);
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
|
||||||
|
|
||||||
assert(memcmp(cache->driver_keys_blob, file_header, ck_size) == 0);
|
ret = read_all(fd, file_header, ck_size);
|
||||||
|
|
||||||
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);
|
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
goto fail;
|
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. */
|
/* Load the CRC that was created when the file was written. */
|
||||||
struct cache_entry_file_data cf_data;
|
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);
|
free(uncompressed_data);
|
||||||
if (filename)
|
if (filename)
|
||||||
free(filename);
|
free(filename);
|
||||||
|
if (file_header)
|
||||||
|
free(file_header);
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue