From b427a5f941ab44dc59d4bc876f32cb1a114814a7 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 11 Oct 2013 22:20:46 +0000 Subject: [PATCH] Fix OpenGL texture cache "leak" and slightly tweak hash string construction. The leak happened because a struct was hashed that had uninitialized bytes in padding inserted by the compiler. The hash string in now constructed as concatenation of three CRC32s as 8-byte hex strings, i.e. the individual CRC32s are padded with leading zeros. Note to users: because of the hash change, it's sensible to delete the 'textures' and 'textures.cache' files. git-svn-id: https://svn.eduke32.com/eduke32@4096 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/texcache.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/polymer/eduke32/build/src/texcache.c b/polymer/eduke32/build/src/texcache.c index b62ebca97..5ec9ea67b 100644 --- a/polymer/eduke32/build/src/texcache.c +++ b/polymer/eduke32/build/src/texcache.c @@ -399,9 +399,13 @@ int32_t texcache_readdata(void *dest, int32_t len) static const char * texcache_calcid(char *cachefn, const char *fn, const int32_t len, const int32_t dameth, const char effect) { + // Assert that BMAX_PATH is a multiple of 4 so that struct texcacheid_t + // gets no padding inserted by the compiler. + EDUKE32_STATIC_ASSERT((BMAX_PATH & 3) == 0); + struct texcacheid_t { int32_t len, method; - char effect, name[BMAX_PATH]; + char effect, name[BMAX_PATH+3]; // +3: pad to a multiple of 4 } id = { len, dameth, effect, "" }; Bstrcpy(id.name, fn); @@ -409,7 +413,7 @@ static const char * texcache_calcid(char *cachefn, const char *fn, const int32_t while (Bstrlen(id.name) < BMAX_PATH - Bstrlen(fn)) Bstrcat(id.name, fn); - Bsprintf(cachefn, "%x%x%x", + Bsprintf(cachefn, "%08x%08x%08x", crc32once((uint8_t *)fn, Bstrlen(fn)), crc32once((uint8_t *)id.name, Bstrlen(id.name)), crc32once((uint8_t *)&id, sizeof(struct texcacheid_t)));