Re: [PATCH RFC 2/3] rust: implement a test balloon via the "varint" subsystem
From: Ben Knoble <hidden>
Date: 2025-09-07 20:07:28
quoted hunk ↗ jump to hunk
Le 4 sept. 2025 à 10:27, Patrick Steinhardt [off-list ref] a écrit : Implement a trivial test balloon for our Rust build infrastructure by reimplementing the "varint.c" subsystem in Rust. This subsystem is chosen because it is trivial to convert and because it doesn't have any dependencies to other components of Git. If support for Rust is enabled, we stop compiling "varint.c" and instead compile and use "src/varint.rs". Signed-off-by: Patrick Steinhardt <redacted> --- meson.build | 5 +++- src/lib.rs | 1 + src/meson.build | 1 + src/varint.rs | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 1 deletion(-)diff --git a/src/varint.rs b/src/varint.rs new file mode 100644 index 00000000000..3d41760a555 --- /dev/null +++ b/src/varint.rs@@ -0,0 +1,92 @@ +use std::os::raw::c_int; +use std::os::raw::c_uchar; + +#[no_mangle] +pub unsafe extern "C" fn decode_varint(bufp: *mut *const c_uchar) -> usize { + let mut buf = *bufp; + let mut c = *buf; + let mut val = usize::from(c & 127); + + buf = buf.add(1); + + while (c & 128) != 0 { + val += 1; + if val == 0 || val.leading_zeros() < 7 { + return 0; // overflow
Hm. I thought overflows panic in debug builds, in which case checking afterwards is too late? Does unsafe change that?