From c987a5a915dbc373aa9dcbbf6ce951240b359404 Mon Sep 17 00:00:00 2001 From: John Coffey Date: Sun, 8 Nov 2026 23:02:06 -0700 Subject: [PATCH] Registry: a stored list skips values this build doesn't know A stored object's permission list, event list or enum-keyed map failed to load whole when it held a value the running build didn't know. A newer release grants its new permissions to the administrator roles it finds, so after an upgrade an older build could no longer read those roles, and a rollback lost every administrator's permissions (the recovery admin still worked). Lists and enum-keyed maps now leave out a value they don't recognize, read past it, and load the rest of the object. A damaged stream is still refused. A role edited and saved on the older build keeps only the permissions that build knows. Test: a Permission list and an enum-keyed map holding an id from a newer build failed to read on main; now the unknown entries are left out, the known ones and the field after them read, and a list cut short is still refused. --- crates/registry/src/pickle.rs | 25 ++++++++++++++-- crates/registry/src/types/map.rs | 49 +++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/crates/registry/src/pickle.rs b/crates/registry/src/pickle.rs index dcfcc9f3..6993724c 100644 --- a/crates/registry/src/pickle.rs +++ b/crates/registry/src/pickle.rs @@ -2,6 +2,8 @@ * SPDX-FileCopyrightText: 2020 Stalwart Labs LLC * * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL + * + * Modified by Coffey Labs in 2026 for INBUXA. */ use crate::types::EnumImpl; @@ -17,6 +19,13 @@ const COMPRESS_WATERMARK: usize = 8192; pub trait Pickle: Sized { fn pickle(&self, out: &mut Vec); fn unpickle(stream: &mut PickledStream<'_>) -> Option; + + /// inbuxa: reads one item of a list or map. `Some(None)` is an item this + /// build doesn't know, a newer version's enum value, read past so the + /// rest of the object still loads; `None` is a damaged stream. + fn unpickle_item(stream: &mut PickledStream<'_>) -> Option> { + Self::unpickle(stream).map(Some) + } } pub struct PickledStream<'x> { @@ -186,6 +195,10 @@ impl Pickle for T { fn unpickle(stream: &mut PickledStream<'_>) -> Option { u16::unpickle(stream).and_then(Self::from_id) } + + fn unpickle_item(stream: &mut PickledStream<'_>) -> Option> { + u16::unpickle(stream).map(Self::from_id) + } } impl Pickle for Option @@ -256,9 +269,13 @@ where let len = u32::unpickle(stream)? as usize; let mut map = VecMap::with_capacity(len); for _ in 0..len { - let key = K::unpickle(stream)?; + let key = K::unpickle_item(stream)?; let value = V::unpickle(stream)?; - map.append(key, value); + // inbuxa: an entry keyed by a value this build doesn't know is + // dropped, its value read past + if let Some(key) = key { + map.append(key, value); + } } Some(map) } @@ -272,4 +289,8 @@ impl Pickle for trc::Key { fn unpickle(stream: &mut PickledStream<'_>) -> Option { u16::unpickle(stream).and_then(Self::from_id) } + + fn unpickle_item(stream: &mut PickledStream<'_>) -> Option> { + u16::unpickle(stream).map(Self::from_id) + } } diff --git a/crates/registry/src/types/map.rs b/crates/registry/src/types/map.rs index af953c15..0db3c496 100644 --- a/crates/registry/src/types/map.rs +++ b/crates/registry/src/types/map.rs @@ -2,6 +2,8 @@ * SPDX-FileCopyrightText: 2020 Stalwart Labs LLC * * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL + * + * Modified by Coffey Labs in 2026 for INBUXA. */ use crate::{ @@ -111,7 +113,12 @@ where let len = u32::unpickle(stream)? as usize; let mut vec = Vec::with_capacity(len); for _ in 0..len { - vec.push(T::unpickle(stream)?); + // inbuxa: a value this build doesn't know (a permission or event + // added by a newer version) is left out instead of failing the + // whole object, so a rollback still loads its roles + if let Some(item) = T::unpickle_item(stream)? { + vec.push(item); + } } Some(Self(vec)) } @@ -432,6 +439,46 @@ mod tests { map } + /// A permission list stored by a newer version: the unknown id is left + /// out and the fields after it still read (rollback to an older build). + #[test] + fn unpickle_skips_unknown_enum_ids() { + use crate::{pickle::PickledStream, schema::enums::Permission}; + use utils::map::vec_map::VecMap; + + let unknown = u16::MAX - 1; + assert!(Permission::from_id(unknown).is_none()); + let mut out = vec![0u8]; + 3u32.pickle(&mut out); + Permission::Authenticate.pickle(&mut out); + unknown.pickle(&mut out); + Permission::SysScheduledReportUpdate.pickle(&mut out); + 2u32.pickle(&mut out); + unknown.pickle(&mut out); + 7u64.pickle(&mut out); + Permission::AuthenticateWithAlias.pickle(&mut out); + 9u64.pickle(&mut out); + "after".to_string().pickle(&mut out); + + let mut stream = PickledStream::new(&out).unwrap(); + let map = Map::::unpickle(&mut stream).unwrap(); + assert_eq!( + map.0, + vec![ + Permission::Authenticate, + Permission::SysScheduledReportUpdate + ] + ); + let vec_map = VecMap::::unpickle(&mut stream).unwrap(); + assert_eq!(vec_map.len(), 1); + assert_eq!(vec_map.get(&Permission::AuthenticateWithAlias), Some(&9)); + assert_eq!(String::unpickle(&mut stream).as_deref(), Some("after")); + + // A list cut short is still refused + let mut stream = PickledStream::new(&out[..4]).unwrap(); + assert!(Map::::unpickle(&mut stream).is_none()); + } + #[test] fn patch_map_id_digit_keys() { for id in [0u64, 28, 29, 70, 861, 954, 957, 30554] { -- 2.54.0