Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This crate fails to decode Vec<u8> #50

Open
Boog900 opened this issue Jun 28, 2023 · 0 comments
Open

This crate fails to decode Vec<u8> #50

Boog900 opened this issue Jun 28, 2023 · 0 comments

Comments

@Boog900
Copy link
Member

Boog900 commented Jun 28, 2023

When de-serializing a sequence this crate goes straight to dispatch_based_on_marker:

fn deserialize_seq<V>(self, visitor: V) -> Result<<V as Visitor<'de>>::Value>
where
V: Visitor<'de>,
{
let marker = self.read_marker()?;
self.dispatch_based_on_marker(marker, visitor)
}

This is wrong for a byte array which is tagged as a string:

fn dispatch_based_on_marker<'de, V>(&mut self, marker: Marker, visitor: V) -> Result<V::Value>
where
V: Visitor<'de>,
{
match marker {
Marker::Sequence {
element: element_marker,
} => visitor.visit_seq(SeqAccess::with_varint_encoded_length(self, element_marker)?),
MARKER_SINGLE_I64 => visitor.visit_i64(self.buffer.read_i64::<LittleEndian>()?),
MARKER_SINGLE_I32 => visitor.visit_i32(self.buffer.read_i32::<LittleEndian>()?),
MARKER_SINGLE_I16 => visitor.visit_i16(self.buffer.read_i16::<LittleEndian>()?),
MARKER_SINGLE_I8 => visitor.visit_i8(self.buffer.read_i8()?),
MARKER_SINGLE_U64 => visitor.visit_u64(self.buffer.read_u64::<LittleEndian>()?),
MARKER_SINGLE_U32 => visitor.visit_u32(self.buffer.read_u32::<LittleEndian>()?),
MARKER_SINGLE_U16 => visitor.visit_u16(self.buffer.read_u16::<LittleEndian>()?),
MARKER_SINGLE_U8 => visitor.visit_u8(self.buffer.read_u8()?),
MARKER_SINGLE_F64 => visitor.visit_f64(self.buffer.read_f64::<LittleEndian>()?),
MARKER_SINGLE_STRING => visitor.visit_string(self.read_varint_string()?),
MARKER_SINGLE_BOOL => visitor.visit_bool(self.read_bool()?),
MARKER_SINGLE_STRUCT => visitor.visit_map(MapAccess::with_varint_encoded_fields(self)?),
_ => Err(Error::unknown_marker(marker)),
}
}

Even with my most recent PRs this is still incorrect, to fix this will require special de-serializing logic for Vec<u8> kinda like we have done in deserialize_tuple.

A work around is to use serde_with::Bytes which is more efficient anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant