mirror of
https://github.com/webmproject/libwebp.git
synced 2025-08-30 07:42:27 +02:00
utils.h: add SizeOverflow()
this normalizes the 'size != (size_t)size' checks in the libraries. Change-Id: I1e8ccd0d3697266f23911ecf0f7a546f011befde
This commit is contained in:
@@ -172,7 +172,7 @@ static int CheckSizeArgumentsOverflow(uint64_t nmemb, size_t size) {
|
||||
const uint64_t total_size = nmemb * size;
|
||||
if (nmemb == 0) return 1;
|
||||
if ((uint64_t)size > WEBP_MAX_ALLOCABLE_MEMORY / nmemb) return 0;
|
||||
if (total_size != (size_t)total_size) return 0;
|
||||
if (!CheckSizeOverflow(total_size)) return 0;
|
||||
#if defined(PRINT_MEM_INFO) && defined(MALLOC_FAIL_AT)
|
||||
if (countdown_to_fail > 0 && --countdown_to_fail == 0) {
|
||||
return 0; // fake fail!
|
||||
@@ -181,7 +181,7 @@ static int CheckSizeArgumentsOverflow(uint64_t nmemb, size_t size) {
|
||||
#if defined(PRINT_MEM_INFO) && defined(MALLOC_LIMIT)
|
||||
if (mem_limit > 0) {
|
||||
const uint64_t new_total_mem = (uint64_t)total_mem + total_size;
|
||||
if (new_total_mem != (size_t)new_total_mem ||
|
||||
if (!CheckSizeOverflow(new_total_mem) ||
|
||||
new_total_mem > mem_limit) {
|
||||
return 0; // fake fail!
|
||||
}
|
||||
|
Reference in New Issue
Block a user