Skip to content

Commit 41cdf83

Browse files
lpcoxCopilot
andauthored
Update guards/github-guard/rust-guard/src/lib.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent eb00a4d commit 41cdf83

File tree

1 file changed

+16
-3
lines changed
  • guards/github-guard/rust-guard/src

1 file changed

+16
-3
lines changed

guards/github-guard/rust-guard/src/lib.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,22 @@ pub extern "C" fn label_response(
761761
// Read input bytes
762762
let input_bytes = unsafe { slice::from_raw_parts(input_ptr as *const u8, input_len as usize) };
763763

764-
// Log first 500 bytes of input to debug structure (safe on char boundary)
765-
if let Ok(full_str) = std::str::from_utf8(input_bytes) {
766-
let preview = safe_preview(full_str, PREVIEW_MAX_BYTES);
764+
// Log a bounded preview of the input for debugging.
765+
// Only decode up to PREVIEW_MAX_BYTES so logging stays cheap, and
766+
// if the prefix ends mid-codepoint, fall back to the valid UTF-8 prefix.
767+
let preview_bytes = &input_bytes[..input_bytes.len().min(PREVIEW_MAX_BYTES)];
768+
let preview = match std::str::from_utf8(preview_bytes) {
769+
Ok(s) => s,
770+
Err(e) => {
771+
let valid_up_to = e.valid_up_to();
772+
if valid_up_to == 0 {
773+
""
774+
} else {
775+
std::str::from_utf8(&preview_bytes[..valid_up_to]).unwrap_or("")
776+
}
777+
}
778+
};
779+
if !preview.is_empty() {
767780
log_info(&format!(" input_preview={}", preview));
768781
}
769782

0 commit comments

Comments
 (0)