From 4c0b1a17e75da85e03388f805acc2a533b6d13e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Mon, 19 Oct 2026 15:49:09 +0300 Subject: [PATCH 1/2] inout: return `PadError` for incorrect `Padding` implementations --- inout/CHANGELOG.md | 7 +++++++ inout/src/reserved.rs | 9 ++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/inout/CHANGELOG.md b/inout/CHANGELOG.md index d95336f6..9fb3ac46 100644 --- a/inout/CHANGELOG.md +++ b/inout/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.2.5 (2026-10-16) +### Fixed +- Return `PadError` from `InOutBufReserved::into_padded_blocks` + for incorrect `Padding` implementations ([#1562]) + +[#1562]: https://github.com/RustCrypto/utils/pull/1562 + ## 0.2.4 (2026-10-16) ### Fixed - Output buffer length check in `InOutBufReserved::into_padded_blocks` ([#1559]) diff --git a/inout/src/reserved.rs b/inout/src/reserved.rs index 101b29f0..e1ee9022 100644 --- a/inout/src/reserved.rs +++ b/inout/src/reserved.rs @@ -168,7 +168,6 @@ impl<'inp, 'out> InOutBufReserved<'inp, 'out, u8> { /// # Errors /// If the padding is invalid #[inline(always)] - #[allow(clippy::missing_panics_doc)] pub fn into_padded_blocks(self) -> Result, PadError> where P: Padding, @@ -197,8 +196,12 @@ impl<'inp, 'out> InOutBufReserved<'inp, 'out, u8> { PaddedData::Error => return Err(PadError), }; - // This invariant must hold for all valid padding implementations. - debug_assert_eq!(blocks.len(), self.in_len / BS::USIZE); + // These invariants must hold for all valid padding implementations. + let expected_ptr = blocks.as_ptr().cast() == self.in_ptr; + let expected_len = blocks.len() == (self.in_len / BS::USIZE); + if !(expected_ptr && expected_len) { + return Err(PadError); + } Ok(PaddedInOutBuf { in_ptr: blocks.as_ptr(), From 5df3821e60cac01ea9d05adfe65be2e308a1c7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Mon, 19 Oct 2026 15:55:42 +0300 Subject: [PATCH 2/2] tweak check --- inout/src/reserved.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/inout/src/reserved.rs b/inout/src/reserved.rs index e1ee9022..d165fadc 100644 --- a/inout/src/reserved.rs +++ b/inout/src/reserved.rs @@ -197,9 +197,10 @@ impl<'inp, 'out> InOutBufReserved<'inp, 'out, u8> { }; // These invariants must hold for all valid padding implementations. - let expected_ptr = blocks.as_ptr().cast() == self.in_ptr; - let expected_len = blocks.len() == (self.in_len / BS::USIZE); - if !(expected_ptr && expected_len) { + if blocks.as_ptr().cast() != self.in_ptr { + return Err(PadError); + } + if blocks.len() != self.in_len / BS::USIZE { return Err(PadError); }