From bdb6ff8881e2f7782d87465b27ec88407b5ffd01 Mon Sep 17 00:00:00 2001 From: "Kimon N." Date: Mon, 27 Apr 2026 01:46:57 +0200 Subject: [PATCH] Keep gguflib input-validation asserts active in release builds (#3436) --- mlx/io/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mlx/io/CMakeLists.txt b/mlx/io/CMakeLists.txt index eebd7618..1fedcd46 100644 --- a/mlx/io/CMakeLists.txt +++ b/mlx/io/CMakeLists.txt @@ -17,6 +17,11 @@ if(MLX_BUILD_GGUF) PRIVATE $) add_library(gguflib STATIC ${gguflib_SOURCE_DIR}/fp16.c ${gguflib_SOURCE_DIR}/gguflib.c) + # gguflib uses assert() to reject malformed tensor headers (e.g. ndim > 8). + # Those checks are otherwise compiled out by -DNDEBUG in release builds, which + # leaves out-of-bounds reads/writes unguarded when loading untrusted GGUF + # files. Force NDEBUG off for this target so the asserts stay live. + target_compile_options(gguflib PRIVATE -UNDEBUG) target_link_libraries(mlx PRIVATE $) target_sources(mlx PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/gguf.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gguf_quants.cpp)