Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions plugins/idb_import/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ struct BinaryViewReader<'a> {
impl std::io::Read for BinaryViewReader<'_> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impl Seek for BinaryReader {
/// Seek to the specified position.
fn seek(&mut self, pos: SeekFrom) -> std::io::Result<u64> {
match pos {
SeekFrom::Current(offset) => self.seek_to_relative_offset(offset),
SeekFrom::Start(offset) => self.seek_to_offset(offset),
SeekFrom::End(end_offset) => {
// We do NOT need to add the image base here as
// the reader (unlike the writer) can set the virtual base.
let offset =
self.view
.len()
.checked_add_signed(end_offset)
.ok_or(std::io::Error::new(
ErrorKind::Other,
"Seeking from end overflowed",
))?;
self.seek_to_offset(offset);
}
};
Ok(self.offset())
}
}
impl Read for BinaryReader {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
let len = buf.len();
let result = unsafe { BNReadData(self.handle, buf.as_mut_ptr() as *mut _, len) };
if !result {
Err(std::io::Error::new(ErrorKind::Other, "Read out of bounds"))
} else {
Ok(len)
}
}
}

As per the discussion we had in this PR swap BinaryViewReader out for the one in bindings

fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
if !self.bv.offset_valid(self.offset) {
return Err(std::io::Error::new(
std::io::ErrorKind::UnexpectedEof,
"Unable to read at the current offset in BinaryViewReader",
));
// TODO check if this is truly a EoF hit, `self.bv.len()` is not
// reliable, it's returning a size bigger then the original file.
return Ok(0);
}
let len = BinaryView::read(self.bv, buf, self.offset);
self.offset += u64::try_from(len).unwrap();
Expand Down
Loading