From 0f1a27dff39e3ac6856e6684f1034475f90ef87d Mon Sep 17 00:00:00 2001 From: Landon Cox Date: Tue, 30 Jun 2026 06:26:45 -0700 Subject: [PATCH 1/3] fix: deduplicate write paths in label_response (#8328) Replace duplicated manual write blocks (unsafe as u32/i32 casts, buffer size checks, write_bytes_to_output calls) in label_response's two output branches with calls to the existing try_write_json_output helper, matching the pattern already used by label_agent and label_resource. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- guards/github-guard/rust-guard/src/lib.rs | 40 +++-------------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/guards/github-guard/rust-guard/src/lib.rs b/guards/github-guard/rust-guard/src/lib.rs index 49f1902e..8dff1d0b 100644 --- a/guards/github-guard/rust-guard/src/lib.rs +++ b/guards/github-guard/rust-guard/src/lib.rs @@ -972,24 +972,8 @@ pub extern "C" fn label_response( let output_preview = safe_preview(&output_json, PREVIEW_MAX_BYTES); log_info(&format!(" path_output_preview={}", output_preview)); - if output_json.len() as u32 > output_size { - log_warn(&format!( - " output buffer too small ({} > {})", - output_json.len(), - output_size - )); - log_info("<<< label_response returning 0 (buffer too small)"); - return 0; - } - - // Write output - unsafe { write_bytes_to_output(output_ptr, output_json.as_bytes()) }; - - log_info(&format!( - "<<< label_response returning {} bytes (path-based)", - output_json.len() - )); - return output_json.len() as i32; + let n = try_write_json_output(&output_json, output_ptr, output_size, "label_response/path"); + return if n < 0 { 0 } else { n }; } // Fall back to legacy item-based labeling for singletons @@ -1034,24 +1018,8 @@ pub extern "C" fn label_response( let output_preview = safe_preview(&output_json, PREVIEW_MAX_BYTES); log_info(&format!(" output_preview={}", output_preview)); - if output_json.len() as u32 > output_size { - log_warn(&format!( - " output buffer too small ({} > {})", - output_json.len(), - output_size - )); - log_info("<<< label_response returning 0 (buffer too small)"); - return 0; - } - - // Write output - unsafe { write_bytes_to_output(output_ptr, output_json.as_bytes()) }; - - log_info(&format!( - "<<< label_response returning {} bytes", - output_json.len() - )); - output_json.len() as i32 + let n = try_write_json_output(&output_json, output_ptr, output_size, "label_response/legacy"); + if n < 0 { 0 } else { n } } // ============================================================================ From cbc7c1aa3f9277a396451b31c0b864551705ad67 Mon Sep 17 00:00:00 2001 From: Landon Cox Date: Tue, 30 Jun 2026 06:32:44 -0700 Subject: [PATCH 2/3] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- guards/github-guard/rust-guard/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/guards/github-guard/rust-guard/src/lib.rs b/guards/github-guard/rust-guard/src/lib.rs index 8dff1d0b..0c9a967a 100644 --- a/guards/github-guard/rust-guard/src/lib.rs +++ b/guards/github-guard/rust-guard/src/lib.rs @@ -973,7 +973,11 @@ pub extern "C" fn label_response( log_info(&format!(" path_output_preview={}", output_preview)); let n = try_write_json_output(&output_json, output_ptr, output_size, "label_response/path"); - return if n < 0 { 0 } else { n }; + if n < 0 { + log_info("<<< label_response returning 0 (output write failed)"); + return 0; + } + return n; } // Fall back to legacy item-based labeling for singletons From f813a703ec043961ff9e3df2c617c9199f1c3c1f Mon Sep 17 00:00:00 2001 From: Landon Cox Date: Tue, 30 Jun 2026 06:32:54 -0700 Subject: [PATCH 3/3] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- guards/github-guard/rust-guard/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/guards/github-guard/rust-guard/src/lib.rs b/guards/github-guard/rust-guard/src/lib.rs index 0c9a967a..1006ce80 100644 --- a/guards/github-guard/rust-guard/src/lib.rs +++ b/guards/github-guard/rust-guard/src/lib.rs @@ -1023,7 +1023,12 @@ pub extern "C" fn label_response( log_info(&format!(" output_preview={}", output_preview)); let n = try_write_json_output(&output_json, output_ptr, output_size, "label_response/legacy"); - if n < 0 { 0 } else { n } + if n < 0 { + log_info("<<< label_response returning 0 (output write failed)"); + 0 + } else { + n + } } // ============================================================================