Skip to content

Commit

Permalink
Fix: Don't zero memory when reading a buffer (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
robert3005 authored Apr 5, 2024
1 parent 8528979 commit 51ec1b3
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions vortex-array/src/serde/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
use std::io;
use std::io::{Cursor, ErrorKind, Read, Write};

use arrow_buffer::buffer::{Buffer, MutableBuffer};
use arrow_buffer::buffer::Buffer;
use arrow_buffer::BooleanBuffer;
use flatbuffers::root;
use itertools::Itertools;
pub use view::*;
use vortex_error::{vortex_err, VortexResult};
use vortex_flatbuffers::{FlatBufferToBytes, ReadFlatBuffer};
use vortex_schema::DTypeSerdeContext;
use vortex_schema::{DType, IntWidth, Nullability, Signedness};

use crate::array::bool::BoolArray;
use crate::array::composite::COMPOSITE_EXTENSIONS;
use crate::array::{Array, ArrayRef};
use crate::compute::ArrayCompute;
use crate::encoding::{find_encoding, EncodingId, ENCODINGS};
use crate::ptype::PType;
use crate::scalar::{Scalar, ScalarReader, ScalarWriter};
Expand All @@ -22,12 +26,6 @@ pub mod data;
mod ptype;
pub mod view;

pub use view::*;
use vortex_flatbuffers::{FlatBufferToBytes, ReadFlatBuffer};

use crate::array::bool::BoolArray;
use crate::compute::ArrayCompute;

pub trait ArraySerde {
fn write(&self, ctx: &mut WriteCtx) -> VortexResult<()>;

Expand Down Expand Up @@ -187,9 +185,9 @@ impl<'a> ReadCtx<'a> {
) -> VortexResult<(usize, Buffer)> {
let logical_len = self.read_usize()?;
let buffer_len = byte_len(logical_len);
let mut buffer = MutableBuffer::from_len_zeroed(buffer_len);
self.r.read_exact(&mut buffer)?;
Ok((logical_len, buffer.into()))
let mut buf = Vec::with_capacity(buffer_len);
self.r.take(buffer_len as u64).read_to_end(&mut buf)?;
Ok((logical_len, Buffer::from_vec(buf)))
}

pub fn read_nbytes<const N: usize>(&mut self) -> VortexResult<[u8; N]> {
Expand Down

0 comments on commit 51ec1b3

Please sign in to comment.