From 43020cbd67847b7c2726cb8fc8dcc28aa0e47b68 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Wed, 14 Oct 2020 01:38:21 +0000 Subject: [PATCH] Fixed Rust code to avoid arithmetic overflow when a segment's bit length is very near usize::MAX. --- rust/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index b247258..88340a1 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1147,7 +1147,8 @@ impl QrSegment { return None; // The segment's length doesn't fit the field's bit width } } - result = result.checked_add(4 + usize::from(ccbits) + seg.data.len())?; + result = result.checked_add(4 + usize::from(ccbits))?; + result = result.checked_add(seg.data.len())?; } Some(result) }