std/webp: tweak workbuf_len determination

This commit is contained in:
Nigel Tao committed 2026-08-10 09:23:05 +10:00
1 parent c4df79d82e
commit 466cf6f15d
12 files changed
+106 -90

No files matched your search

+3
View File
@@ -518,6 +518,9 @@ redirect:
// Allocate the work buffer. Wuffs' decoders conventionally assume that this
// can be uninitialized memory.
wuffs_base__range_ii_u64 workbuf_len = image_decoder->workbuf_len();
if (workbuf_len.is_empty()) {
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
}
DecodeImageCallbacks::AllocWorkbufResult alloc_workbuf_result =
callbacks.AllocWorkbuf(workbuf_len, true);
if (!alloc_workbuf_result.error_message.empty()) {
+2
View File
@@ -162,6 +162,8 @@ class DecodeImageCallbacks {
// should be at least len_range.min_incl, but larger allocations (up to
// len_range.max_incl) may have better performance (by using more memory).
//
// The len_range argument will satisfy !len_range.is_empty().
//
// The default AllocWorkbuf implementation allocates len_range.max_incl bytes
// of either uninitialized or zeroed memory.
virtual AllocWorkbufResult //
+6 -1
View File
@@ -230,7 +230,12 @@ wuffs_drop_in__stb__load1( //
}
uint64_t pixbuf_len = (uint64_t)w * (uint64_t)h * (uint64_t)desired_channels;
uint64_t workbuf_len = wuffs_base__image_decoder__workbuf_len(dec).max_incl;
wuffs_base__range_ii_u64 r = wuffs_base__image_decoder__workbuf_len(dec);
if (wuffs_base__range_ii_u64__is_empty(&r)) {
wuffs_drop_in__stb__g_failure_reason = "indeterminate workbuf length";
return NULL;
}
uint64_t workbuf_len = r.max_incl;
#if SIZE_MAX < 0xFFFFFFFFFFFFFFFFull
if ((pixbuf_len > ((uint64_t)SIZE_MAX)) ||
(workbuf_len > ((uint64_t)SIZE_MAX))) {