Bounds the memory a small corrupt/truncated file claiming a huge image can make the loader allocate
before Wuffs fails. Images within the 16384 dimension cap that need a larger work buffer (the largest
progressive JPEGs, ~>9.4K^2 CMYK 4:4:4 / ~>10.9K^2 YCbCr 4:4:4, and 8-bit RGBA PNGs right at 16384^2)
are now rejected with the work-buffer error. Still overridable with -DBASISU_WUFFS_LDR_MAX_WORKBUF_BYTES.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
load_png(mem), load_tga(file), load_jpg(file/mem) and load_qoi(mem/file) now
go through a thin Wuffs C-API adapter (wuffs_load_ldr) when
BASISU_USE_WUFFS_LDR_LOADER is 1 (the default, basisu_enc.h). Everything
built on them (load_image, load_image_hdr's LDR paths, basis_compressor,
the basisu tool, KTX2 Studio's WASM encoder) switches automatically. The
old pvpngreader / read_tga() / jpgd / qoi.h decode bodies stay in #else
branches (=0 gives today's code; qoi.h is still used to write .QOI).
The adapter only converts to basisu's RGBA image, enforces the caps and
reports errors. Wuffs' accept/reject and pixels are final: no fallback,
no fixups. decode_image_config reads the header, then a 0 width/height
("empty image"), width/height > BASISU_WUFFS_LDR_MAX_DIM (default
basist::BASISU_MAX_SUPPORTED_TEXTURE_DIMENSION = 16384) or a work buffer >
BASISU_WUFFS_LDR_MAX_WORKBUF_BYTES (default 3 GiB here, the measured worst
case at 16384^2; tradeoff documented in basisu_enc.h) is refused BEFORE any
pixel or work buffer is allocated. All memory is basisu's own
(image::try_alloc - added here - and try_resize, initialized); img is only
replaced on success; nothing asserts on file data.
get_ldr_image_info() is a header-only query (no cap) that returns the
true dimensions, even of files beyond the decode cap.
Wuffs is declared here (wuffs-v0.4.c included without
WUFFS_IMPLEMENTATION, same config header) and compiled in
encoder/3rdparty/basisu_wuffs.cpp.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
basisu_wuffs.cpp defines WUFFS_IMPLEMENTATION and #includes the unmodified
encoder/3rdparty/wuffs-v0.4.c with all warnings silenced in that TU only
(MSVC #pragma warning(push, 0)/pop; gcc/clang diagnostic push/ignored/pop).
basisu_wuffs_config.h holds the Wuffs configuration (modules BASE core/
interfaces/pixconv, ADLER32, CRC32, DEFLATE, ZLIB, PNG, JPEG, TARGA, QOI;
RGBA_NONPREMUL destination only; WUFFS_CONFIG__AVOID_CPU_ARCH = no SIMD), shared
with basisu_enc.cpp's declarations-only include (next commit). With
BASISU_USE_WUFFS_LDR_LOADER=0 the TU compiles to nothing.
Added to every build that compiles the encoder: root CMakeLists.txt
(native, -m32, WASI, Python module) with a BASISU_USE_WUFFS_LDR_LOADER option
(default ON), webgl/encoder/CMakeLists.txt (all Emscripten variants, same
option), and encoder_lib.vcxproj/.filters (basisu.sln: basisu, examples).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
encoder/3rdparty/wuffs-v0.4.c is the verbatim release/c/wuffs-v0.4.c from
github.com/google/wuffs at commit 4be865da258c (WUFFS_VERSION_STRING
"0.4.0-alpha.12+4048.20261020"), sha256
458066457347bd6d9bc3c906aa8292bea4488577727569ddd9436fdd89d5f04d.
Wuffs is dual-licensed Apache-2.0 OR MIT; basis_universal elects
Apache-2.0 (same as the rest of the repo, LICENSES/Apache-2.0.txt):
added to .reuse/dep5 and the README's 3rd-party sentence. Wuffs ships no
NOTICE file. Not compiled yet (the next commits add the build files and
the loader adapter).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- 3 subset CEM 7/11 partition compression needs to check for rare failures
- adding clamp to bc6h encoder's smooth block weight index assigner (assign_weights_simple_4)