The sanity check on a level's m_uncompressed_byte_length (>= 2 GiB)
logged "Invalid level offset (too large)", which names the wrong field.
Correct it to "Invalid level uncompressed byte length (too large)".
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Two things prevented the transcoder from compiling with
BASISD_SUPPORT_KTX2 set to 0:
- ktx2_image_level_info was defined inside the #if BASISD_SUPPORT_KTX2
block, but dds_transcoder::get_image_level_info() takes it by
reference and is compiled unconditionally. Move the struct ahead of
that block so it is always defined; it has no KTX2-specific members.
- The "#include ../zstd/zstd.h" was nested inside #if BASISD_SUPPORT_KTX2,
but the Zstd decompressor (zstd_decompress()) is compiled whenever
BASISD_SUPPORT_KTX2_ZSTD is set, independent of KTX2 (Zstd is also used
by other codecs). With KTX2 off but Zstd on, the ZSTD_* symbols were
referenced without the header being included. Gate the include on
BASISD_SUPPORT_KTX2_ZSTD alone, matching where the symbols are used.
BASISD_SUPPORT_KTX2_ZSTD still defaults to 1 (unchanged). The default
build (KTX2 and Zstd both enabled) is unaffected.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The KTX2 level and supercompression-global-data (SGD) offset/length
fields are full 64-bit values read from the file. init() validated them
with "offset + length > m_data_size", where the addition can wrap around
and incorrectly pass for out-of-range values. Rewrite both checks as
"offset > m_data_size || length > (uint64_t)m_data_size - offset", which
cannot overflow (offset is confirmed <= m_data_size before the
subtraction, so it can't underflow either). The result is identical to
the original for every in-range input.
Also in init():
- Reject a level whose byte_length is 0. This case already logged an
error but fell through without returning false.
- Add KTX2_MAX_SUPPORTED_LAYER_COUNT (65535) and reject files whose
layer_count exceeds it, mirroring KTX2_MAX_SUPPORTED_LEVEL_COUNT, so
layer_count * face_count * level_count stays bounded.
read_slice_offset_len_global_data(): compute image_count in 64-bit,
verify m_sgd_byte_length == image_count * descriptor_size before sizing
the descriptor array, and use try_resize() (returns false on failure)
instead of resize() (which aborts the process) so an out-of-range count
fails cleanly instead of attempting an oversized allocation. Also
compute image_count in 64-bit in decompress_etc1s_global_data().
Valid files are handled exactly as before.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
container_abort() calls std::terminate() but the file does not include <exception>. This compiles on most toolchains today because other headers transitively pull it in, but fails on Android NDK r28 (Clang 19) with C++23 where the transitive include no longer happens.
Same class of issue as #395 (missing <ctype.h> in this file).
- 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)
This update impacts the UASTC HDR 4x4, UASTC HDR 6x6i, and XUASTC LDR formats. New KTX2 files in these specific formats using v2.1 can't be loaded using v2.0, however we've kept backwards compatibility with all of our previously written KTX2 files. (v2.1 can transcode all previously written files.)
This is part of our effort to be compatible with Khronos's specification.
bc6hf encoder's smooth block path updated to handle inputs with texels close to MAX_HALF_FLOAT.
Adding command line options to basisu tool so it can write either v2.0 or v1.6 compatible UASTC HDR 6x6i files. The default is v1.6.
Updating WebGL KTX2 testbed so on ASTC devices it automatically switches between sRGB or linear internal formats for the created texture.
PR 408's cmakelists.txt file has too many issues (OpenCL breaks on Windows/OSX) and changing our options to have the "BASISU_" prefix will break upstream builds.
transcoder/basisu_astc_helpers.h has a pragma once, but it is also an
implementation header (when ASTC_HELPERS_IMPLEMENTATION is defined).
pragma once is not necessary here as the header has a separate ifdef
guard, and it blocks attempts to compile Basis as a CMake Unity build
(CMAKE_UNITY_BUILD=ON) or as a single-translation unit non-CMake build
if the helpers header has been included earlier in the TU, as the second
inclusion with implementation defined doesn't actually include the
header.
Fixing overflow issue on extreme colors in color_distance().
Explicitly disabling unaligned addressing in miniz and transcoder when UBSAN is enabled
Disabling a needless optimization in transcoder causing ubsan issues (that could have easily been worked around in a different way, but it was an unnecessary optimization to begin with)
Rebuild wasm builds