mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-11-29 03:26:12 +00:00
new_sd_ctx(), generate_image() and generate_video() now record the reason of a failure, and sd_get_last_error() returns it with a code: out of memory, model file, backend, invalid argument, busy or cancelled. An application can tell "try again with less memory" from "the file is damaged" instead of reading the log. The state belongs to the calling thread; errors logged by the model loader threads reach the thread that reports the failure. C++ exceptions, std::bad_alloc included, no longer cross the C API. A test with a limited address space showed the process ending with std::terminate when a loader thread could not be created while others were already running. The loader now uses fewer threads, or the calling thread when none could be started, and the loader threads report exceptions as a failed load. sd_get_system_memory() returns total, available and process RAM. The free memory of the CPU device in sd_get_device_info() is the available RAM, because ggml reports the total on Linux and macOS. Checked with a synthetic 2.1 GB SD 1.5 model under a limited address space: the standard configuration fails with out_of_memory, the same context generates once the limit is lifted, and weights on disk let the same request succeed. The Windows branch of system_memory.cpp was only syntax-checked; macOS was not built. Claude-Session: https://claude.ai/code/session_01EhZzDBkuuMp1jBf4WtEySC |
||
|---|---|---|
| .. | ||
| api_robustness.cpp | ||
| file_handle_pool_test.cpp | ||
| fuzz_model_loader.py | ||
| pe_imports_test.cpp | ||
| README.md | ||
| security_smoke.sh | ||
Test di robustezza e sicurezza (fork)
Script locali di questo fork per verificare che il motore fallisca in modo pulito con input ostili, senza crash né errori di memoria. Istruzioni complete in italiano: docs/integrazione_progetti.md, sezione "Sicurezza".
| Test | Cosa verifica | Come si esegue |
|---|---|---|
security_smoke.sh |
file modello ostili + opzioni CLI estreme → mai crash (exit < 128) | ./test/security_smoke.sh build/bin/sd-cli |
api_robustness.cpp |
API C: puntatori nulli, indici fuori range, buffer piccoli, stress multi-thread (con ASan/UBSan) | vedi intestazione del file |
pe_imports_test.cpp |
lettore della tabella di importazione dei file PE (diagnostica delle DLL mancanti su Windows): file validi, troncati e corrotti (con ASan/UBSan) | vedi intestazione del file |
file_handle_pool_test.cpp |
pool dei flussi aperti sui file modello: riuso, file modificato o sostituito, flussi in errore, limiti, uso concorrente (con ASan/UBSan e TSan) | vedi intestazione del file |
fuzz_model_loader.py |
fuzzing a mutazione del caricamento modelli (safetensors/GGUF) | python3 test/fuzz_model_loader.py <sd-cli> --seconds 300 |
Per il fuzzing è consigliata una build con AddressSanitizer:
cmake -B build_asan -DCMAKE_BUILD_TYPE=RelWithDebInfo -DSD_WEBP=OFF -DSD_WEBM=OFF \
-DCMAKE_C_FLAGS=-fsanitize=address -DCMAKE_CXX_FLAGS=-fsanitize=address \
-DCMAKE_EXE_LINKER_FLAGS=-fsanitize=address
cmake --build build_asan -j --target sd-cli
python3 test/fuzz_model_loader.py build_asan/bin/sd-cli --seconds 600
Gli input che causano una scoperta vengono salvati in test/fuzz_findings/
(da non committare). Questi test riducono il rischio ma non dimostrano
l'assenza di vulnerabilità.