Code Monkey home page Code Monkey logo

cdr-rs's People

Contributors

danieleades avatar dependabot[bot] avatar frehberg avatar hrektts avatar jrebelo avatar kydos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cdr-rs's Issues

Serializing without encapsulation

I'd like to implement a GIOP/IIOP interface using this crate. However, there is no 4-byte encapsulation header in this protocol; the byte order is marked in the encoded stream (in non-byte-order-sensitive types).

Would it be possible to introduce API to encode without the header, and to specify the encapsulation in the decode call? Otherwise I can't use the _into/_from APIs and have to use allocations.

char/none size calculation irritating

Two issues in size.rs I see the following code.

First:

   fn serialize_char(self, v: char) -> Result<Self::Ok> {
        self.add_size(v.len_utf8() as u64)
    }

A char in CDR is always u8, it is irritating, that code code here is assuming a dynamic size depending on utf encoding

AFAICS, it should be:

 fn serialize_char(self, v: char) -> Result<Self::Ok> {
        // no alignment required increment byte-size 1
        self.add_size(1 as u8)
 }

Second:

Another weird thing is this code, it will add byte-size of u8 to the counte (1)r, but according to name it should add 0!?

    fn serialize_none(self) -> Result<Self::Ok> {
        self.add_value(0 as u8)
    }

Address Clippy Warnings

Hello,

First of thanks for contributing the CDR codec, this has helped us a lot in getting zenoh (see https://github.com/eclipse-zenoh/zenoh and http://zenoh.io) seamlessly read/write data from DDS and ROS2.

As a little contribution on our side, we'd like to eliminate all clippy warning, as you'll see by running cargo clippy there is at least one that is quite important on the de.rs | read_vec.

I'll do a pull request right off with the fixes. Ideally would be good to have cargo clippy run as part of the GitHub actions.

Thanks!

  • kydos

64 bits integers should be serialized as i32/u32 pair

In the CDR described in the RTPS standard, all 64 bit integers are serialized as an i32 representing the high part (most significant 32 bits) and a u32 representing low part (least significant 32 bits). See for example section 9.4.2.5 Sequence Number in DDSI-RTPS version 2.3 standard.

If I am not mistaken, the implementation in this library serializes these 64 bit objects as a complete set of 8 octets.

I am not sure if your objective is to follow closely the RTPS serialization but I wondered if it would be a possibility to change the current implementation to match the RTPS serialization of 64 bit objects?

Reading uninitialized memory can cause UB (`Deserializer::read_vec`)

Hello ๐Ÿฆ€ ,
we (Rust group @sslab-gatech) found a memory-safety/soundness issue in this crate while scanning Rust code on crates.io for potential vulnerabilities.

Issue Description

cdr-rs/src/de.rs

Lines 70 to 77 in 880a281

fn read_vec(&mut self) -> Result<Vec<u8>> {
let len: u32 = de::Deserialize::deserialize(&mut *self)?;
let mut buf = Vec::with_capacity(len as usize);
unsafe { buf.set_len(len as usize) }
self.read_size(u64::from(len))?;
self.reader.read_exact(&mut buf[..])?;
Ok(buf)
}

Deserializer::read_vec method creates an uninitialized buffer and passes it to user-provided Read implementation (self.reader.read_exact). This is unsound, because it allows safe Rust code to exhibit an undefined behavior (read from uninitialized memory).

Suggested Fix

It is safe to zero-initialize the newly allocated part of u8 buffer before read(), in order to prevent user-provided Read from getting access to the old contents from the newly allocated heap memory.

Thank you for checking out this issue ๐Ÿ‘

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.