Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

fix: V-001 security vulnerability

anupamme02c2d09e3652
diff --git a/c/kimi_k3.c b/c/kimi_k3.c
index 7b847f63..34ba89ef 100644
--- a/c/kimi_k3.c
+++ b/c/kimi_k3.c
@@ -284,8 +284,12 @@ static double rss_gb(void){ struct rusage r; getrusage(RUSAGE_SELF,&r);
return r.ru_maxrss/(1024.0*1024.0);
#endif
}
-static float *falloc(int64_t n){ float *p=malloc((size_t)n*sizeof(float)); if(!p){fprintf(stderr,"OOM %lld floats\n",(long long)n);exit(1);} return p; }
-static float *fcalloc(int64_t n){ float *p=calloc((size_t)n,sizeof(float)); if(!p){fprintf(stderr,"OOM %lld floats\n",(long long)n);exit(1);} return p; }
+static float *falloc(int64_t n){
+ if(n<0 || (uint64_t)n > SIZE_MAX/sizeof(float)){ fprintf(stderr,"alloc size overflow: %lld floats\n",(long long)n); exit(1); }
+ float *p=malloc((size_t)n*sizeof(float)); if(!p){fprintf(stderr,"OOM %lld floats\n",(long long)n);exit(1);} return p; }
+static float *fcalloc(int64_t n){
+ if(n<0 || (uint64_t)n > SIZE_MAX/sizeof(float)){ fprintf(stderr,"alloc size overflow: %lld floats\n",(long long)n); exit(1); }
+ float *p=calloc((size_t)n,sizeof(float)); if(!p){fprintf(stderr,"OOM %lld floats\n",(long long)n);exit(1);} return p; }
/* Aligned + zeroed alloc. Metal's wrap() only takes the zero-copy (newBufferWithBytesNoCopy)
* path when the pointer AND size are 16384-aligned; otherwise it makes a private GPU copy
* that is never synced back. Buffers the GPU WRITES and must persist across tokens (KDA