Patch for quickcheck 1.0, fixing some testing issues

epel10
Benjamin A. Beasley 6 months ago
parent 16cec54c20
commit edc4b10da2

@ -0,0 +1,54 @@
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 || {

@ -0,0 +1,8 @@
--- arrayref-0.3.8/Cargo.toml 1970-01-01T00:00:01+00:00
+++ arrayref-0.3.8/Cargo.toml 2024-09-03T14:21:24.860504+00:00
@@ -20,4 +20,4 @@
repository = "https://github.com/droundy/arrayref"
[dev-dependencies.quickcheck]
-version = "0.6"
+version = "1.0"

@ -12,6 +12,16 @@ Summary: Macros to take array references of slices
License: BSD-2-Clause License: BSD-2-Clause
URL: https://crates.io/crates/arrayref URL: https://crates.io/crates/arrayref
Source: %{crates_source} Source: %{crates_source}
# Manually created patch for downstream crate metadata changes
# * Update dev-dependency on quickcheck from 0.6 to 1.0
Patch: arrayref-fix-metadata.diff
# Fix bounds math issues in tests revealed by quickcheck v1
# https://github.com/droundy/arrayref/pull/28/commits/af5a9154bde9eef7475d1f622bae8851333ad336
# Fixes:
# test::check_array_ref_5 and test::check_array_mut_ref_7 fail with
# quickcheck@1.0.3
# https://github.com/droundy/arrayref/issues/22
Patch: https://github.com/droundy/arrayref/pull/28/commits/af5a9154bde9eef7475d1f622bae8851333ad336.patch
BuildRequires: cargo-rpm-macros >= 24 BuildRequires: cargo-rpm-macros >= 24

Loading…
Cancel
Save