1 Commits

Author SHA1 Message Date
lazypool 4366038c23 fix spirv compile failure diagnostics read past shader buffer (#6882)
* fix spirv compile failure diagnostics read past shader buffer (#6881)

the shader source slice passed to glslang (comp_datas[3]) is not
null-terminated, since the .comp_data arrays generated by
ncnn_generate_shader_comp_header.cmake are hex-encoded without a
trailing 0x00. the error-printing path in compile_spirv_module()
scanned it with strchr() and checked *p != '\0', causing an
out-of-bounds read and garbled diagnostics whenever a shader fails
to compile.

bound the scan with memchr() using the known source length and print
the trailing partial line with %.*s instead of relying on
null-termination. verified with asan: before, a broken non-null-
terminated shader source reports a stack-buffer-overflow in
compile_spirv_module(); after, the error path prints correctly with
no overrun.

* fix bounded shader version parsing and add regression tests

---------

Signed-off-by: lazypool <lazypool@proton.me>
Co-authored-by: Marcin Sochacki <136440930+marcin-sochacki@users.noreply.github.com>
Co-authored-by: nihui <nihuini@tencent.com>
2026-09-15 21:49:34 +08:00