Skip to content

Attempt to add with overflow #376

Description

@CodeMarco05

The scenario. When a huge data chunk needs to be serialized. First it takes a very very long time and then the following issue occurs.

attempt to add with overflow
thread 'data_storage::file_format::block::tests::creation_with_data_too_big_test' (778007) panicked at /Users//.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rmp-serde-1.3.1/src/encode.rs:527:17:
attempt to add with overflow

it is in the encode this function:

fn serialize_element<T: ?Sized + Serialize>(&mut self, value: &T) -> Result<(), Self::Error> {
  match self.compound.as_mut() {
      None => value.serialize(&mut *self.se),
      Some(buf) => {
          value.serialize(&mut buf.se)?;
          buf.elem_count += 1;
          Ok(())
      },
  }
}

I think the fix would be to increase the the elem_count from u32 to an u64 for good measure.
Current:

#[derive(Debug)]
struct UnknownLengthCompound {
    se: Serializer<Vec<u8>, DefaultConfig>,
    elem_count: u32,
}

I can myself do this change and create a pull request. Though it is this small, so maybe you can fix it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions