Skip to content

Validate GGUF tensor dimensions#3447

Open
abhirup7 wants to merge 2 commits intoml-explore:mainfrom
abhirup7:fix-gguf-ndim-validation
Open

Validate GGUF tensor dimensions#3447
abhirup7 wants to merge 2 commits intoml-explore:mainfrom
abhirup7:fix-gguf-ndim-validation

Conversation

@abhirup7
Copy link
Copy Markdown

@abhirup7 abhirup7 commented Apr 24, 2026

Fixes #3358.

Summary

  • Reject GGUF tensors whose ndim exceeds GGUF_TENSOR_MAX_DIM before converting tensor dimensions to an MLX shape, including both values in the error message.
  • Add a regression test for malformed GGUF tensor rank.
  • Compile gguflib sources directly into mlx via target_sources so downstream static-link consumers don't hit unresolved symbols, and expose gguflib headers only to MLX sources and the GGUF-specific test via BUILD_INTERFACE.

Tests

clang-format -i mlx/io/gguf.cpp tests/load_tests.cpp
cmake -S . -B build-cpu -DMLX_BUILD_TESTS=ON -DMLX_BUILD_PYTHON_BINDINGS=OFF -DMLX_BUILD_METAL=OFF -DMLX_BUILD_EXAMPLES=OFF -DMLX_BUILD_BENCHMARKS=OFF
cmake --build build-cpu --target tests -j8
./build-cpu/tests/tests -tc="test gguf tensor ndim validation"
./build-cpu/tests/tests -tc="test gguf*"
git diff --check

@abhirup7 abhirup7 force-pushed the fix-gguf-ndim-validation branch from efb087e to 9e2acbb Compare April 24, 2026 07:01
@abhirup7 abhirup7 force-pushed the fix-gguf-ndim-validation branch from 9e2acbb to 40bcaea Compare April 24, 2026 08:15
Drop the intermediate OBJECT library target and fold gguflib sources
directly into mlx via target_sources, and propagate the include path
through BUILD_INTERFACE directly on the mlx and tests targets.
@abhirup7 abhirup7 force-pushed the fix-gguf-ndim-validation branch from 25d28a5 to 9ff0d34 Compare April 24, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] get_shape() has no bounds check allowing read of outside data structure

1 participant