From f92e6706c4a265d74b7d36c9a07ba3507bf1ae6d Mon Sep 17 00:00:00 2001 From: mintsuki Date: Sun, 5 Mar 2023 09:08:37 +0100 Subject: [PATCH] compress/gz: Add hack to allow macOS compressed GZs to load with stbi --- common/compress/tinfgzip.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/common/compress/tinfgzip.c b/common/compress/tinfgzip.c index b34c77ce..67776660 100644 --- a/common/compress/tinfgzip.c +++ b/common/compress/tinfgzip.c @@ -116,7 +116,15 @@ void *tinf_gzip_uncompress(const void *source, uint64_t sourceLen, uint64_t *out void *buf = ext_mem_alloc(dlen); - res = stbi_zlib_decode_noheader_buffer(buf, dlen, (const char *)start, (src + sourceLen) - start - 8); + // XXX for some reason certain GZ files made by macOS do not properly decompress with stb_image + // unless some skew (19 bytes?) is applied to the buffer. I have no idea why this is the + // case but I'd rather have them load somewhat than not load at all. + for (uint64_t skew = 0; skew < 32; skew++) { + res = stbi_zlib_decode_noheader_buffer(buf, dlen, (const char *)start + skew, (src + sourceLen) - start - 8 - skew); + if (res != -1) { + break; + } + } if (res == -1) { pmm_free(buf, dlen);