Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
57 changes: 28 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ prost = "0.14.0"
prost-build = "0.14.0"
rustc-demangle = "0.1"
serde_json = "1"
sha2 = "0.10"
sha2 = "0.11"
tempfile = "3"
thiserror = "2"
zstd = "0.13.0"
Expand Down
10 changes: 7 additions & 3 deletions rust-crates/symblib/src/fileid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use base64::Engine;
use sha2::digest::FixedOutput;
use sha2::Digest as _;
use std::io::Read as _;
use std::{fmt, fs, io, path};

/// Size of the head and tail blocks used for partially hashing ELF files.
Expand Down Expand Up @@ -44,12 +43,17 @@ impl FileId {

// Hash first 4096 bytes.
stream.seek(io::SeekFrom::Start(0))?;
io::copy(&mut stream.by_ref().take(PARTIAL_HASH_SIZE), &mut hasher)?;
let mut buf = [0u8; 4096];
let to_read = (PARTIAL_HASH_SIZE as usize).min(buf.len());
let n = stream.read(&mut buf[..to_read])?;
hasher.update(&buf[..n]);

// Hash last 4096 bytes.
let tail_start = stream_len.saturating_sub(PARTIAL_HASH_SIZE);
stream.seek(io::SeekFrom::Start(tail_start))?;
io::copy(&mut stream.by_ref().take(PARTIAL_HASH_SIZE), &mut hasher)?;
let to_read = (PARTIAL_HASH_SIZE as usize).min(buf.len());
let n = stream.read(&mut buf[..to_read])?;
hasher.update(&buf[..n]);

// Hash length.
hasher.update(u64::to_be_bytes(stream_len));
Expand Down
Loading