tafia / quick-protobuf

A rust implementation of protobuf parser
MIT License
446 stars 82 forks source link

Adding message length twice #222

Closed kckeiks closed 1 year ago

kckeiks commented 1 year ago

Given the definition of sizeof_len below, I noticed that we are also adding the length again when allocating vec capacity in serialize_into_vec. I think this might be a mistake?

https://github.com/tafia/quick-protobuf/blob/d977371e05170a016f03a80512b2a925468e3a1a/quick-protobuf/src/writer.rs#L313

pub fn sizeof_len(len: usize) -> usize {
    sizeof_varint(len as u64) + len
}
snproj commented 1 year ago

Yep, thanks for catching that! I'll make the PR to fix this soon.

If I'm not wrong, I also think serialize_into_slice() checks out.len() < len, which doesn't account for the length of the length varint itself.