From cbb8ebefa446200f7867b128d8c7766ee309ab10 Mon Sep 17 00:00:00 2001 From: Richard Geldreich Date: Sat, 8 Nov 2025 11:28:34 -0500 Subject: [PATCH] Fixing ftell() error handling issue introduced by warning merge from PR 408 --- encoder/3rdparty/qoi.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/encoder/3rdparty/qoi.h b/encoder/3rdparty/qoi.h index 5c6de08..d39c68e 100644 --- a/encoder/3rdparty/qoi.h +++ b/encoder/3rdparty/qoi.h @@ -631,14 +631,30 @@ void *qoi_read(const char *filename, qoi_desc *desc, int channels) { #endif size_t size, bytes_read; void *pixels, *data; + long sz; if (!f) { return NULL; } fseek(f, 0, SEEK_END); - size = ftell(f); - if (size <= 0 || fseek(f, 0, SEEK_SET) != 0) { + + sz = ftell(f); + if (sz <= 0) + { + fclose(f); + return NULL; + } + + size = (size_t)sz; + + if (size != sz) + { + fclose(f); + return NULL; + } + + if (fseek(f, 0, SEEK_SET) != 0) { fclose(f); return NULL; }