From 3fb8a44e55f0fd4fa2938794e5a38b60f19b1705 Mon Sep 17 00:00:00 2001 From: Beyley Cardellio Date: Thu, 2 Oct 2025 15:13:19 -0700 Subject: [PATCH] Prevent passing NULL to memcpy parameter in parsing resources This behaviour is UB in C, even if byte count is zero. --- spirv_reflect.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/spirv_reflect.c b/spirv_reflect.c index bc43485..2350bcb 100644 --- a/spirv_reflect.c +++ b/spirv_reflect.c @@ -3572,9 +3572,16 @@ static SpvReflectResult ParseStaticallyUsedResources(SpvReflectPrvParser* p_pars ++j; } - memcpy(&p_used_accesses[used_acessed_count], p_parser->functions[j].accessed_variables, - p_parser->functions[j].accessed_variable_count * sizeof(SpvReflectPrvAccessedVariable)); - used_acessed_count += p_parser->functions[j].accessed_variable_count; + SpvReflectPrvFunction* p_function = &p_parser->functions[j]; + + // Prevent NULL from being passed to memcpy, which is UB + if (p_function->accessed_variable_count == 0) { + continue; + } + + memcpy(&p_used_accesses[used_acessed_count], p_function->accessed_variables, + p_function->accessed_variable_count * sizeof(SpvReflectPrvAccessedVariable)); + used_acessed_count += p_function->accessed_variable_count; } SafeFree(p_called_functions);