From bc3aac677f883081272a8cf96143248ff5e7b3d0 Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 25 Jan 2023 23:17:30 +0800 Subject: [PATCH] fix zero-length key readback error in bulk reads zero-length keys return a data section of None, instead of Some(), as the latter representation deserializes to a null pointer panic. --- services/pddb/src/api.rs | 7 ++++--- services/pddb/src/lib.rs | 3 ++- services/pddb/src/main.rs | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/services/pddb/src/api.rs b/services/pddb/src/api.rs index 3fab0e010..df88f3b9b 100644 --- a/services/pddb/src/api.rs +++ b/services/pddb/src/api.rs @@ -376,9 +376,10 @@ pub struct PddbKeyRecord { pub age: usize, pub index: NonZeroU32, pub basis: String, - /// If this is None, it means that the data read exceeded the bulk read limit - /// and the record must be explicitly re-read with a non-bulk call to fetch its data. - /// If the key is actually zero-length, a zero-length Some(Vec) is returned. + /// If this is None, it means either that the data read exceeded the bulk read limit + /// and the record must be explicitly re-read with a non-bulk call to fetch its data, + /// or the key has zero length. Check the `len` field to differentiate the two. + /// (Turns out that `rkyv` crashes when deserializing a zero-length Vec) pub data: Option>, } diff --git a/services/pddb/src/lib.rs b/services/pddb/src/lib.rs index a3c4f4f5d..227de45d3 100644 --- a/services/pddb/src/lib.rs +++ b/services/pddb/src/lib.rs @@ -801,7 +801,8 @@ impl Pddb { /// Retrieve an entire dictionary of data in a single call. Will return data records up to but not /// over a total of `size_limit`. Keys that exceed the limit are still enumerated, but their - /// data sections are `None`, instead of `Some(Vec::)`. + /// data sections are `None`, instead of `Some(Vec::)`. Keys that are zero-length are also returned + /// with a data section of `None`; check the `len` field of the PddbKeyRecord to determine which is which. /// Defaults to a size limit of up to 32k of bulk data returned, if it is not explicitly specified. pub fn read_dict(&self, dict: &str, basis: Option<&str>, size_limit: Option) -> Result> { // about the biggest we can move around in Precursor and not break heap. diff --git a/services/pddb/src/main.rs b/services/pddb/src/main.rs index 97f7a320e..7f4b7e0f4 100644 --- a/services/pddb/src/main.rs +++ b/services/pddb/src/main.rs @@ -1586,7 +1586,7 @@ fn wrapped_main() -> ! { age: attr.age, index: attr.index, basis: attr.basis, - data: Some(d) + data: if d.len() > 0 { Some(d) } else { None } }; state.read_total += attr.len; // commit the read length early let (prebuf, sbuf) = buf.split_at_mut(size_of::()*2);