From 77e7878f7bbc38fffd1ec024182f56098ca4d92d Mon Sep 17 00:00:00 2001 From: Afloat <132809511+Afloat16@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:38:14 -0500 Subject: [PATCH] dex: Address the parser review findings from #722 (#766) Port Craft Anything eab6a0f01bf9fc3a36798d322e4442e169394dfc reader and opcode decoder. --- crates/dex/src/dex.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/dex/src/dex.rs b/crates/dex/src/dex.rs index b01a1b247..6b23d2e78 100644 --- a/crates/dex/src/dex.rs +++ b/crates/dex/src/dex.rs @@ -156,14 +156,14 @@ pub fn mutf8(r: &Reader<'_>, mut at: usize, max_units: usize) -> (String, usize) (String::from_utf16_lossy(&units), consumed) } -/// Signed LEB128 at `off`: (value, bytes). +/// Signed 32-bit DEX LEB128 at `off`: (value, bytes), using at most five bytes. pub fn sleb128(r: &Reader<'_>, off: usize) -> Option<(i64, usize)> { let mut result = 0i64; let mut shift = 0u32; - for i in 0..10usize { + for i in 0..5usize { let b = r.u8(off.checked_add(i)?)?; - // Only one value bit remains in the tenth byte; the rest must extend its sign. - if i == 9 && !matches!(b, 0x00 | 0x7f) { + // Four value bits remain in byte five; the other bits must extend the sign. + if i == 4 && !matches!(b, 0x00..=0x07 | 0x78..=0x7f) { return None; } result |= i64::from(b & 0x7f).checked_shl(shift)?;