Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ggml-cpu: Add bounds checking in make_block_q4_0x4 function #1095

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ilhamsyahids
Copy link

Prevent potential buffer overflows by adding explicit bounds checking when copying memory in the make_block_q4_0x4 function

after:

~/ggml/build$ cmake --build . --config Release -j 8
[  1%] Building CXX object examples/CMakeFiles/common.dir/common.cpp.o
[  2%] Building C object src/CMakeFiles/ggml-base.dir/ggml.c.o
[  3%] Building C object src/CMakeFiles/ggml-base.dir/ggml-alloc.c.o
[  4%] Building CXX object src/CMakeFiles/ggml-base.dir/ggml-backend.cpp.o
[  6%] Building CXX object src/CMakeFiles/ggml-base.dir/ggml-opt.cpp.o
[  6%] Building CXX object src/CMakeFiles/ggml-base.dir/ggml-threading.cpp.o
[  7%] Building C object src/CMakeFiles/ggml-base.dir/ggml-quants.c.o
[  8%] Building CXX object src/CMakeFiles/ggml-base.dir/gguf.cpp.o
[  9%] Linking CXX shared library libggml-base.so
[  9%] Built target ggml-base
[ 10%] Building CXX object src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu.cpp.o
[ 11%] Building C object src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu.c.o
[ 12%] Building CXX object src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu-aarch64.cpp.o
[ 13%] Building CXX object src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu-hbm.cpp.o
[ 14%] Building CXX object src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu-traits.cpp.o
[ 15%] Building C object src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu-quants.c.o
[ 16%] Building CXX object src/CMakeFiles/ggml-cpu.dir/ggml-cpu/amx/amx.cpp.o
[ 17%] Building CXX object src/CMakeFiles/ggml-cpu.dir/ggml-cpu/amx/mmq.cpp.o
[ 18%] Linking CXX static library libcommon.a
[ 18%] Built target common
[ 19%] Linking CXX shared library libggml-cpu.so
[ 19%] Built target ggml-cpu
[ 20%] Building CXX object src/CMakeFiles/ggml.dir/ggml-backend-reg.cpp.o
[ 21%] Linking CXX shared library libggml.so
[ 21%] Built target ggml
...

Prevent potential buffer overflows by adding explicit bounds checking when copying memory in the `make_block_q4_0x4` function

Signed-off-by: Ilham Syahid S <[email protected]>
Copy link
Member

@slaren slaren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor the memory copying logic in the `make_block_q4_0x4` function to remove explicit bounds checking
Use compile-time constants and loop bounds to prevent potential buffer overflows.

Signed-off-by: Ilham Syahid S <[email protected]>
@ilhamsyahids
Copy link
Author

I understand it could be potentially expensive checks, therefore I simplify it on 6bd5fb2

could you please check? @slaren

@ilhamsyahids ilhamsyahids requested a review from slaren February 4, 2025 08:25
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.

Potentially buffer overflow in make_block_q4_0x4
2 participants