Skip to content

Commit cc552f5

Browse files
committed
Fix integer underflow in append_subst
Even though it would immediately re-overflow into a valid value, apparently we have the rust overflow checks enabled on release builds in android, causing crashes.
1 parent 38aeca3 commit cc552f5

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src-rs/strutil.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl Pattern {
161161
if let Some(subst_percent_index) = memchr(b'%', subst) {
162162
let mut ret = BytesMut::with_capacity(subst.len() + s.len() - self.pat.len() + 1);
163163
ret.put_slice(&subst[..subst_percent_index]);
164-
ret.put_slice(&s[percent_index..(percent_index + s.len() - self.pat.len() + 1)]);
164+
ret.put_slice(&s[percent_index..(percent_index + s.len() + 1 - self.pat.len())]);
165165
ret.put_slice(&subst[subst_percent_index + 1..]);
166166
return ret.into();
167167
}
@@ -555,6 +555,7 @@ mod test {
555555
assert_eq!(subst_pattern(b"x.c", b"x.c", b"OK"), "OK");
556556
assert_eq!(subst_pattern(b"x.c.c", b"x.c", b"XX"), "x.c.c");
557557
assert_eq!(subst_pattern(b"x.x.c", b"x.c", b"XX"), "x.x.c");
558+
assert_eq!(subst_pattern(b"/", b"%/", b"%"), "");
558559
}
559560

560561
#[test]

0 commit comments

Comments
 (0)