From f17cd9bd3772c23bf38130293ed01a0e4cc51fe3 Mon Sep 17 00:00:00 2001 From: Nicolas Sarlin Date: Tue, 9 Dec 2025 09:36:20 +0100 Subject: [PATCH] fix(integer): handle message mod 0 in num_blocks --- tfhe/src/integer/ciphertext/utils.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tfhe/src/integer/ciphertext/utils.rs b/tfhe/src/integer/ciphertext/utils.rs index 57171e8a3..b2dbeb503 100644 --- a/tfhe/src/integer/ciphertext/utils.rs +++ b/tfhe/src/integer/ciphertext/utils.rs @@ -25,6 +25,9 @@ impl DataKind { Self::Unsigned(n) | Self::Signed(n) => n.get(), Self::Boolean => 1, Self::String { n_chars, .. } => { + if message_modulus.0 == 0 { + return 0; + } let blocks_per_char = 7u32.div_ceil(message_modulus.0.ilog2()); (n_chars * blocks_per_char) as usize } @@ -95,3 +98,20 @@ impl Expandable for BooleanBlock { } } } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_string_num_blocks() { + let kind = DataKind::String { + n_chars: 10, + padded: true, + }; + + let num_blocks = kind.num_blocks(MessageModulus(0)); + + assert_eq!(num_blocks, 0); + } +}