Skip to content

fix: msgpack::skip_value used to return Ok in case buffer ended

Georgy Moshkin requested to merge gmoshkin/skip_value-error into master

Summary

  • fix: msgpack::skip_value used to return Ok in case buffer ended

The bug was due to the fact that Cursor will seek beyond the end of buffer and will not return an error in that case. It should be handled in our code.

From Seek docs:

A seek beyond the end of a stream is allowed, but behavior is defined by the implementation.

Cursor implementation of Seek::seek:

    fn seek(&mut self, style: SeekFrom) -> io::Result<u64> {
        let (base_pos, offset) = match style {
            SeekFrom::Start(n) => {
                self.pos = n;
                return Ok(n);
            }
            SeekFrom::End(n) => (self.inner.as_ref().len() as u64, n),
            SeekFrom::Current(n) => (self.pos, n),
        };
        match base_pos.checked_add_signed(offset) {
            Some(n) => {
                self.pos = n;
                Ok(self.pos)
            }
            None => Err(io::const_io_error!(
                ErrorKind::InvalidInput,
                "invalid seek to a negative or overflowing position",
            )),
        }
    }

Ensure that

  • New code is covered by tests
  • API is documented
  • Changelog is up to date
  • Version is bumped in the appropriate Cargo.toml files
Edited by Егор Ивков

Merge request reports