fix: address CRIT security findings (CRIT-01 to CRIT-04)#7
fix: address CRIT security findings (CRIT-01 to CRIT-04)#7manni07 wants to merge 1 commit intomaderix:mainfrom
Conversation
- CRIT-01: dlopen() return check + NSClassFromString validation in ane_init()
(ane_runtime.h + stories_config.h); g_ane_ok / g_ane_ok_large flag
only set when all private classes load successfully; stories_config.h
gets re-entry guard (g_ane_init_done) that was previously missing
- CRIT-02: g_ane_ok guard in ane_compile() and compile_kern_mil_w(); NULL check
for inMemoryModel after inMemoryModelWithDescriptor: — prevents crash
when API call returns nil (ane_runtime.h, stories_io.h)
- CRIT-03: Validate fread() return for critical config/header reads to prevent
garbage malloc() sizes; fopen() NULL check in save_checkpoint();
design decision documented (model.h, train_large.m)
- CRIT-04: int -> size_t in build_blob*/build_blob_t/build_blob_fp16; calloc()
NULL checks added; (size_t) cast in malloc() size calculations to
prevent signed integer overflow UB (stories_io.h, model.h)
Simulation: 3 iterations, overall score 96.15% (all criteria >= 95%)
ref: docs/reports/security-audit-2026-03-02.md
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad119aed46
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| LayerWeights *lw, LayerAdam *la, float *rms_final, AdamState *arms_final, | ||
| float *embed, AdamState *aembed) { | ||
| FILE *f = fopen(path, "wb"); | ||
| if (!f) { fprintf(stderr, "save_checkpoint: cannot open %s\n", path); return; } // CRIT-03 |
There was a problem hiding this comment.
Propagate checkpoint open failures before restart
save_checkpoint now returns early when fopen fails, but the training loop still unconditionally restarts with --resume after calling it. In environments where the checkpoint path is unwritable (read-only path, full disk, permission issue), this means the process restarts without a fresh checkpoint and then resumes from stale or missing state, which can repeat work or loop from step 0 indefinitely. Return a success flag here and block the restart path when checkpoint creation fails.
Useful? React with 👍 / 👎.
…rotector-strong, format-security flags, NULL guards on ane_compile/fread/fopen, tokenize.py input validation
Summary
ane_runtime.h,stories_config.h):dlopen()Return-Check;NSClassFromString()Validierung; neueg_ane_ok/g_ane_ok_largeFlags (nurtruewenn alle 4 Private-Classes geladen);stories_config.herhält Re-Entry-Guard (g_ane_init_done)ane_runtime.h,stories_io.h):g_ane_ok-Guard am Anfang vonane_compile()undcompile_kern_mil_w(); NULL-Check fürinMemoryModelnachinMemoryModelWithDescriptor:(verhindert Crash beihexStringIdentifier)model.h,train_large.m):fread()Return-Check für kritische Config/Header-Reads als Gatekeeper vormalloc();fopen()NULL-Check insave_checkpoint(); Designentscheid dokumentiertstories_io.h,model.h):int→size_tin allenbuild_blob*Funktionen;calloc()NULL-Checks;(size_t)-Cast inmalloc()-Größen verhindert UB durch signed integer overflowTest plan
make trainundmake train_largeohne neue Warnings/Errorsmake verify-flags— Security-Flags weiterhin aktiv"model: config read failed"auf stderrsave_checkpointauf read-only path →"save_checkpoint: cannot open"auf stderrCFLAGS_DEBUG(AddressSanitizer) für Laufzeit-Validierung