Repository navigation
fix(cuda-core): return an error on interior NUL in module loading - #1492
Open
alejandro-soto-franco wants to merge 2 commits into
Open
alejandro-soto-franco wants to merge 2 commits into
alejandro-soto-franco wants to merge 2 commits into
Conversation
Eight module-loading paths called CString::new(..).unwrap() in functions that return Result<_, DriverError>. A PTX source, path or symbol name with an interior NUL byte aborted the caller with a panic. Add error::c_string, which maps NulError to CUDA_ERROR_INVALID_VALUE, and use it in CudaContext::load_module_from_ptx_src, load_module_from_file, CudaModule::load_function and get_global, in Device::load_module_from_ptx_src, and in the cudarc_shim module helpers. The conversion runs before the context is bound. The "Panics" sections become "Errors" sections. Signed-off-by: Alejandro Soto Franco <sotofranco.eng@gmail.com>
alejandro-soto-franco
requested review from
elibol,
kkraus14,
nihalpasham and
rparolin
as code owners
October 11, 2026 14:44
c_string drops one NUL in the final byte. PTX read back from NVRTC with its terminator now loads. Any other NUL still returns INVALID_VALUE. Device::load_module_from_file converts the name before it binds the context. Every other entry point already did. module::load takes a &CStr. The full input table lives in the error.rs unit test. The shim and GPU tests check one bad string per call site. The GPU test also loads a terminated source and resolves terminated names.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Eight module-loading paths in cuda-core call
CString::new(..).unwrap()inside functions that returnResult<_, DriverError>. A PTX source, file path or symbol name with an interior NUL byte panics in the caller where the signature promises an error.error::c_string, which mapsNulErrortoCUDA_ERROR_INVALID_VALUE.CudaContext::load_module_from_ptx_src,load_module_from_file,CudaModule::load_functionandget_global.Device::load_module_from_ptx_srcand thecudarc_shim::modulehelpers.c_string, a driver-free test for the shim helpers, and a GPU test intests/simt_module_interior_nul.rscovering the fourCudaContextandCudaModulemethods.Test:
cargo test -p cuda-corepasses (48 unit tests, 3 new integration tests, all other suites) on an RTX 5060 Laptop. The three integration tests fail with a panic at the oldunwrapsites without the change.cargo fmt --checkandcargo clippy --workspace --all-targets -- -D warningsare clean.