You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.2 KiB
55 lines
2.2 KiB
6 months ago
|
From af5a9154bde9eef7475d1f622bae8851333ad336 Mon Sep 17 00:00:00 2001
|
||
|
From: "Benjamin A. Beasley" <code@musicinmybrain.net>
|
||
|
Date: Tue, 3 Sep 2024 10:11:29 -0400
|
||
|
Subject: [PATCH] Fix bounds math issues in tests revealed by quickcheck v1
|
||
|
|
||
|
Some tests relied on unsigned arithmetic that could wrap around, and
|
||
|
quickcheck 1.0 was able to reveal the problem. All of the issues were in
|
||
|
the tests rather than in the implementation.
|
||
|
|
||
|
Fixes #22. Fixes compatibility with quickcheck v1.
|
||
|
---
|
||
|
src/lib.rs | 8 ++++----
|
||
|
1 file changed, 4 insertions(+), 4 deletions(-)
|
||
|
|
||
|
diff --git a/src/lib.rs b/src/lib.rs
|
||
|
index 7b6d4c0..1746f69 100644
|
||
|
--- a/src/lib.rs
|
||
|
+++ b/src/lib.rs
|
||
|
@@ -339,7 +339,7 @@ mod test {
|
||
|
#[test]
|
||
|
fn check_array_ref_5() {
|
||
|
fn f(data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
|
||
|
- if data.len() < offset + 5 {
|
||
|
+ if data.len() < 5 || data.len() - 5 < offset {
|
||
|
return quickcheck::TestResult::discard();
|
||
|
}
|
||
|
let out = array_ref!(data, offset, 5);
|
||
|
@@ -351,7 +351,7 @@ mod test {
|
||
|
#[test]
|
||
|
fn check_array_ref_out_of_bounds_5() {
|
||
|
fn f(data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
|
||
|
- if data.len() >= offset + 5 {
|
||
|
+ if data.len() >= 5 && data.len() - 5 >= offset {
|
||
|
return quickcheck::TestResult::discard();
|
||
|
}
|
||
|
quickcheck::TestResult::must_fail(move || {
|
||
|
@@ -364,7 +364,7 @@ mod test {
|
||
|
#[test]
|
||
|
fn check_array_mut_ref_7() {
|
||
|
fn f(mut data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
|
||
|
- if data.len() < offset + 7 {
|
||
|
+ if data.len() < 7 || data.len() - 7 < offset {
|
||
|
return quickcheck::TestResult::discard();
|
||
|
}
|
||
|
let out = array_mut_ref!(data, offset, 7);
|
||
|
@@ -377,7 +377,7 @@ mod test {
|
||
|
#[test]
|
||
|
fn check_array_mut_ref_out_of_bounds_32() {
|
||
|
fn f(mut data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
|
||
|
- if data.len() >= offset + 32 {
|
||
|
+ if data.len() >= 32 && data.len() - 32 >= offset {
|
||
|
return quickcheck::TestResult::discard();
|
||
|
}
|
||
|
quickcheck::TestResult::must_fail(move || {
|