ComfyUI/tests-unit/comfy_test
Vishnu Jayavel 3b5af89abf Fix confusing ValueError when VAELoader (aimdo mmap path) reads a truncated safetensors file
comfy.utils.load_safetensors() (used by VAELoader and other loaders when
the DynamicVRAM/aimdo backend is active) never validated that the
memory-mapped file actually contained as many bytes as the safetensors
header declared. When a .safetensors file was truncated -- e.g. still
downloading, or an interrupted/partial download -- Python's silent slice
clipping handed torch.frombuffer() a short buffer, producing the
inscrutable low-level error:

    ValueError: buffer length (N bytes) after offset (0 bytes) must be
    a multiple of element size (4)

instead of the clear "corrupt/incomplete file" message already produced
by the sibling (non-aimdo) safetensors.safe_open() code path for the same
underlying condition.

This adds an explicit bounds check against the header's declared data
size and raises the same friendly, actionable ValueError used elsewhere
in load_torch_file() for corrupt/incomplete files.

Fixes #14784 (reported by xnx20050723-lgtm).

Since comfy_aimdo's ModelMMAP requires a compiled, GPU-platform-specific
native backend unavailable in CI/dev environments without a real GPU, the
added test monkeypatches ModelMMAP with a fake backed by a real,
synthetic, truncated safetensors buffer, letting
comfy.utils.load_safetensors() itself be exercised deterministically.
Verified revert-proof: reverting the fix reproduces the exact reported
error string, `buffer length (37 bytes) after offset (0 bytes) must be a
multiple of element size (4)`.
2026-07-17 00:19:27 -07:00
..
folder_path_test.py add models-directory launch argument (#9113) 2026-07-08 22:20:47 +08:00
load_safetensors_test.py Fix confusing ValueError when VAELoader (aimdo mmap path) reads a truncated safetensors file 2026-07-17 00:19:27 -07:00
model_detection_test.py [feat]Add JoyImageEdit native model support (#14428) 2026-07-15 23:48:28 -04:00
seedvr_vae_forward_test.py Add SeedVR2 support (CORE-6) (#14424) 2026-07-10 15:07:42 +08:00
test_seedvr2_dtype.py Try to fix some issues with the seedvr VAE. (#14877) 2026-07-10 19:54:28 -04:00
test_seedvr2_internals.py Add SeedVR2 support (CORE-6) (#14424) 2026-07-10 15:07:42 +08:00
test_seedvr2_model.py Add SeedVR2 support (CORE-6) (#14424) 2026-07-10 15:07:42 +08:00
test_seedvr2_vae_decode.py Add SeedVR2 support (CORE-6) (#14424) 2026-07-10 15:07:42 +08:00
test_seedvr2_vae_tiled.py Try to fix some issues with the seedvr VAE. (#14877) 2026-07-10 19:54:28 -04:00