Giter Site home page Giter Site logo

flumedb-rs's People

Contributors

ahdinosaur avatar cryptix avatar mycognosist avatar pietgeursen avatar sbillig avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

flumedb-rs's Issues

Reading on uninitialized buffer may cause UB ( `read_entry()` )

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

fn read_entry<F>(frame: &Frame, read_at: &mut F) -> Result<ReadResult, Error>
where
F: FnMut(&mut [u8], u64) -> io::Result<usize>,
{
// Entry is [payload size: u64, payload ]
let mut buf = Vec::with_capacity(frame.data_size);
unsafe { buf.set_len(frame.data_size) };
let n = read_at(&mut buf, frame.data_start())?;

fn read_entry<ByteType, F>(frame: &Frame, read_at: &mut F) -> Result<ReadResult, Error>
where
F: FnMut(&mut [u8], u64) -> io::Result<usize>,
{
// Entry is [payload size: u32, payload, payload_size: u32, next_offset: ByteType]
let tail_size = size_of_frame_tail::<ByteType>();
let to_read = frame.data_size + tail_size;
let mut buf = Vec::with_capacity(to_read);
unsafe { buf.set_len(to_read) };
let n = read_at(&mut buf, frame.data_start())?;

Methods go_offset_log::read_entry() & offset_log::read_entry() create an uninitialized buffer and passes it to user-provided F . This is unsound, because it allows safe Rust code to exhibit an undefined behavior (read from uninitialized memory).

This part from the Read trait documentation explains the issue:

It is your responsibility to make sure that buf is initialized before calling read. Calling read with an uninitialized buf (of the kind one obtains via MaybeUninit<T>) is not safe, and can lead to undefined behavior.

Suggested Fix

It is safe to zero-initialize the newly allocated u8 buffer before read_at(), in order to prevent user-provided code from accessing old contents of the newly allocated heap memory.

Also, there are two nightly features for handling such cases.

Thank you for checking out this issue ๐Ÿ‘

Store the entire JSON message instead of just the content.

This will use slightly more disk space but means we don't need to go and hit the offset log for the entire message if needed.

To save some space in the future, we could store the message using cbor and transcode to json if needed.

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.