Enviar #1050809: mozilla-ai llamafile 9a716e7 Out-of-boundsinformación

Títulomozilla-ai llamafile 9a716e7 Out-of-bounds
Descripciónllamafile embeds model weights inside its own executable as a zip archive, and llamafile_open_zip() in llamafile/llamafile.c parses that container by hand. It takes the weights window, an offset and a length, from the zip central directory and never checks either value against the actual size of the file on disk. There are two ways to reach it. The first is a type confusion. get_zip_cfile_offset() and get_zip_cfile_compressed_size() both return int64_t and both use -1 to signal failure, for instance when the compressed size field holds the zip64 sentinel 0xFFFFFFFF but no zip64 extra field is present to satisfy it. Both results are assigned straight into unsigned types, uint64_t and size_t respectively. A crafted archive therefore sets file->size to SIZE_MAX. The following mapping arithmetic, file->mapsize = skew + file->size, wraps to skew - 1, so mmap succeeds and maps a single page, and llamafile_size() reports SIZE_MAX from that point on. The second needs no sentinel at all. There is no test anywhere in the function that the declared offset plus the declared size fits inside the file, so an ordinary oversized size field maps far past the end of the file and is reported as the model size. The consequence is larger than a crash in the container parser. llamafile applies its own patches to the vendored llama.cpp so that gguf_init_from_file() and llama_file::impl() obtain the file extent through this API. The fabricated size therefore becomes llama.cpp's nbytes_remain in ggml/src/gguf.cpp and llama_file::size() in src/llama-mmap.cpp. Those feed llama.cpp's own defences against a crafted GGUF, specifically the "size > nbytes_remain" check and the "offs + ggml_nbytes(tensor) > file->size()" check in llama-model-loader.h. At SIZE_MAX both comparisons are vacuous, so the container layer disables upstream's crafted-model guards before llama.cpp has a chance to apply them. The guard bypass was confirmed at the gguf metadata layer. It was not traced through to a controlled write at the tensor layer and no such claim is made. Reproduction is a 162 byte archive. The crafted file differs from a working control in exactly four bytes, at offsets 95 to 98, where the central directory compressed size field 40 00 00 00 becomes FF FF FF FF. llamafile -m gguf-control.zip --cli -p hi -n 1 exits 2, rejected cleanly llamafile -m gguf-crafted.zip --cli -p hi -n 1 SIGSEGV Tested against a build of commit 9a716e7 on two hosts. On Fedora 43 x86_64 it is a SIGSEGV with a core dump; on arm64 macOS it surfaces as SIGBUS. Ten runs out of ten crash on the crafted archive and zero out of ten on the control. A second archive using a plain oversized size field rather than the zip64 sentinel also segfaults, so a fix that only special cases SIZE_MAX would be incomplete. Two smaller out-of-bounds reads live in the same parser and were confirmed under AddressSanitizer. A central directory whose size field is zero is accepted as long as the record count is nonzero, which leads to malloc(0) followed by a four byte read at llamafile.c:151, and there is a two byte read in zip.c:38. The attack requires no privileges and no user action beyond opening an untrusted file, which is the ordinary way llamafile is used. llamafile's own security documentation names a bug in the GGUF parser as exactly the compromise scenario its sandbox exists to contain, and states that GPU mode runs with no sandbox at all, calling that the common production case. A patch was attached to the report as pull request https://github.com/mozilla-ai/llamafile/pull/1039 (merged upstream on 2026-08-05). It preserves the real file length that the code already obtains via lseek, rejects the negative accessor results before they reach unsigned types, bounds the declared window with a subtraction that cannot overflow, and requires a nonzero central directory size. Verified on both hosts: the crafted archives are rejected zero out of ten, and a genuine Qwen2.5-0.5B llamafile built with the project's own zipalign tool loads and generates byte-identical output before and after the change.
Fuente⚠️ https://github.com/mozilla-ai/llamafile/issues/1038
Usuario
 m00dy (UID 97162)
Sumisión2026-10-21 23:09 (hace 1 mes)
Moderación2026-11-19 23:14 (29 days later)
EstadoAceptado
Entrada de VulDB440918 [mozilla-ai llamafile hasta .0.10.5 Container Parser llamafile/llamafile.c llamafile_open_zip size divulgación de información]
Puntos20

Are you interested in using VulDB?

Download the whitepaper to learn more about our service!