From 9724d650daf6f7167b5ea8e493955b0e4a062433 Mon Sep 17 00:00:00 2001 From: Zhou Wei Date: Mon, 19 Jan 2026 16:00:56 +0800 Subject: [PATCH 1/3] refactor: make remaining bytes validation conditional on strict mode --- src/any.rs | 7 +++++-- src/atom.rs | 12 ++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/any.rs b/src/any.rs index 89bb47e..9d72b60 100644 --- a/src/any.rs +++ b/src/any.rs @@ -103,8 +103,11 @@ macro_rules! any { }, }; - if body.has_remaining() { - return Err(Error::UnderDecode(header.kind)); + + if cfg!(feature = "strict") || cfg!(test) { + if body.has_remaining() { + return Err(Error::UnderDecode(header.kind)); + } } buf.advance(size); diff --git a/src/atom.rs b/src/atom.rs index 7c1b4b2..3d15974 100644 --- a/src/atom.rs +++ b/src/atom.rs @@ -63,8 +63,10 @@ impl DecodeMaybe for T { Err(err) => return Err(err), }; - if body.has_remaining() { - return Err(Error::UnderDecode(T::KIND)); + if cfg!(feature = "strict") || cfg!(test) { + if body.has_remaining() { + return Err(Error::UnderDecode(T::KIND)); + } } buf.advance(size); @@ -142,8 +144,10 @@ impl DecodeAtom for T { Err(err) => return Err(err), }; - if body.has_remaining() { - return Err(Error::UnderDecode(T::KIND)); + if cfg!(feature = "strict") || cfg!(test) { + if body.has_remaining() { + return Err(Error::UnderDecode(T::KIND)); + } } buf.advance(size); From beac3a0994764883fca82540e31dfad45d6ba720 Mon Sep 17 00:00:00 2001 From: Zhou Wei Date: Mon, 19 Jan 2026 16:39:27 +0800 Subject: [PATCH 2/3] fix: resolve clippy warnings --- src/any.rs | 7 ++----- src/atom.rs | 12 ++++-------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/any.rs b/src/any.rs index 9d72b60..6163fa0 100644 --- a/src/any.rs +++ b/src/any.rs @@ -103,11 +103,8 @@ macro_rules! any { }, }; - - if cfg!(feature = "strict") || cfg!(test) { - if body.has_remaining() { - return Err(Error::UnderDecode(header.kind)); - } + if (cfg!(feature = "strict") || cfg!(test)) && body.has_remaining() { + return Err(Error::UnderDecode(header.kind)); } buf.advance(size); diff --git a/src/atom.rs b/src/atom.rs index 3d15974..19b724f 100644 --- a/src/atom.rs +++ b/src/atom.rs @@ -63,10 +63,8 @@ impl DecodeMaybe for T { Err(err) => return Err(err), }; - if cfg!(feature = "strict") || cfg!(test) { - if body.has_remaining() { - return Err(Error::UnderDecode(T::KIND)); - } + if (cfg!(feature = "strict") || cfg!(test)) && body.has_remaining() { + return Err(Error::UnderDecode(T::KIND)); } buf.advance(size); @@ -144,10 +142,8 @@ impl DecodeAtom for T { Err(err) => return Err(err), }; - if cfg!(feature = "strict") || cfg!(test) { - if body.has_remaining() { - return Err(Error::UnderDecode(T::KIND)); - } + if (cfg!(feature = "strict") || cfg!(test)) && body.has_remaining() { + return Err(Error::UnderDecode(T::KIND)); } buf.advance(size); From 9f698b9265e1da623be5b3e4b1b6f73dde9be46c Mon Sep 17 00:00:00 2001 From: Zhou Wei Date: Wed, 21 Jan 2026 20:38:10 +0800 Subject: [PATCH 3/3] refactor: make remaining bytes validation conditional on strict mode in read_from() --- src/atom.rs | 2 +- src/tokio/atom.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/atom.rs b/src/atom.rs index 19b724f..d544231 100644 --- a/src/atom.rs +++ b/src/atom.rs @@ -95,7 +95,7 @@ impl ReadFrom for Option { Err(err) => return Err(err), }; - if body.has_remaining() { + if (cfg!(feature = "strict") || cfg!(test)) && body.has_remaining() { return Err(Error::UnderDecode(T::KIND)); } diff --git a/src/tokio/atom.rs b/src/tokio/atom.rs index 0c57acc..ce63db5 100644 --- a/src/tokio/atom.rs +++ b/src/tokio/atom.rs @@ -37,7 +37,7 @@ impl AsyncReadFrom for Option { Err(err) => return Err(err), }; - if buf.has_remaining() { + if (cfg!(feature = "strict") || cfg!(test)) && buf.has_remaining() { return Err(Error::UnderDecode(T::KIND)); }