From 8baade1f9a313255bb12e7b818a9bdb41f0b34bf Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Wed, 11 Feb 2026 12:43:00 +0100 Subject: [PATCH] frodo-kem: return error instead of panicking on empty serde input Indexing v[0] on empty input panics with index out of bounds. Use split_first() to return a deserialization error instead. --- frodo-kem/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/frodo-kem/src/lib.rs b/frodo-kem/src/lib.rs index 6e100c3..a8e153c 100644 --- a/frodo-kem/src/lib.rs +++ b/frodo-kem/src/lib.rs @@ -215,10 +215,11 @@ macro_rules! serde_impl { where E: serde::de::Error, { + let (&tag, value) = v + .split_first() + .ok_or_else(|| serde::de::Error::custom("empty input"))?; let algorithm = - Algorithm::try_from(v[0]).map_err(serde::de::Error::custom)?; - - let value = &v[1..]; + Algorithm::try_from(tag).map_err(serde::de::Error::custom)?; algorithm .$from_method(value) .map_err(serde::de::Error::custom)