jdhart81 commited on
Commit
6a9c7ee
·
verified ·
1 Parent(s): d162ed2

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +55 -0
README.md ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+
5
+ # SD-CPP-001: stable-diffusion.cpp GGUFReader Process Crash PoC
6
+
7
+ **Security Research — Responsible Disclosure**
8
+
9
+ ## Vulnerability
10
+
11
+ Three input validation failures in `src/gguf_reader.hpp` (GGUFReader class) of [stable-diffusion.cpp](https://github.com/leejet/stable-diffusion.cpp) allow an attacker to crash any process loading a malformed GGUF file.
12
+
13
+ | Bug | Line | Root Cause | Impact |
14
+ |-----|------|-----------|--------|
15
+ | 1 | 62 | `std::string key(key_len, '\0')` with no bound check | `std::length_error` uncaught -> `std::terminate()` |
16
+ | 2 | 140 | `info.name.resize(name_len)` with no bound check | `std::bad_alloc` not caught by `catch(runtime_error)` |
17
+ | 3 | 155 | `shape[3] *= shape[4]` signed int64 multiply | Undefined behavior (signed overflow) |
18
+
19
+ **Commit**: d6dd6d7b555c233bb9bc9f20b4751eb8c9269743
20
+
21
+ ## Reproduction
22
+
23
+ ```bash
24
+ python3 poc_sd_cpp_gguf_reader.py
25
+ # Generates 3 PoC files (32-92 bytes each)
26
+
27
+ # Build stable-diffusion.cpp from source
28
+ git clone https://github.com/leejet/stable-diffusion.cpp
29
+ cd stable-diffusion.cpp && mkdir build && cd build
30
+ cmake .. && cmake --build . --config Debug
31
+
32
+ # Trigger crash
33
+ ./bin/sd --model /path/to/poc_metadata_oob.gguf -p "test" -o /dev/null
34
+ # Expected: "terminate called after throwing an instance of 'std::length_error'"
35
+ ```
36
+
37
+ ## Trigger Condition
38
+
39
+ GGUFReader is a fallback parser invoked when `gguf_init_from_file()` fails (model.cpp:419). A GGUF file with version=999 triggers this fallback reliably. The fallback parser performs zero validation on length fields read from the file.
40
+
41
+ ## Suggested Fix
42
+
43
+ Add upper-bound validation before string allocations and widen the catch block:
44
+
45
+ ```cpp
46
+ // Line 62: bound key_len
47
+ if (key_len > 65536) { LOG_ERROR("key_len too large"); return false; }
48
+
49
+ // Line 214: catch all exceptions, not just runtime_error
50
+ } catch (const std::exception& e) {
51
+ ```
52
+
53
+ ## Reporter
54
+
55
+ Viridis Security (Justin Hart) — viridisnorthllc@gmail.com