forked from gimli-rs/object
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
read: check that sizes are smaller than the file length in ReadCache (g…
…imli-rs#630) This avoids large allocations due to invalid sizes in corrupted files.
- Loading branch information
1 parent
edd8ad0
commit e3c37f0
Showing
4 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use object::Object; | ||
use std::path::Path; | ||
use std::path::PathBuf; | ||
|
||
#[cfg(feature = "std")] | ||
fn get_buildid(path: &Path) -> Result<Option<Vec<u8>>, object::read::Error> { | ||
let file = std::fs::File::open(path).unwrap(); | ||
let reader = object::read::ReadCache::new(file); | ||
let object = object::read::File::parse(&reader)?; | ||
object | ||
.build_id() | ||
.map(|option| option.map(ToOwned::to_owned)) | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
#[test] | ||
/// Regression test: used to attempt to allocate 5644418395173552131 bytes | ||
fn get_buildid_bad_elf() { | ||
let path: PathBuf = [ | ||
"testfiles", | ||
"elf", | ||
"yara-fuzzing", | ||
"crash-7dc27920ae1cb85333e7f2735a45014488134673", | ||
] | ||
.iter() | ||
.collect(); | ||
let _ = get_buildid(&path); | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
#[test] | ||
fn get_buildid_less_bad_elf() { | ||
let path: PathBuf = [ | ||
"testfiles", | ||
"elf", | ||
"yara-fuzzing", | ||
"crash-f1fd008da535b110853885221ebfaac3f262a1c1e280f10929f7b353c44996c8", | ||
] | ||
.iter() | ||
.collect(); | ||
let buildid = get_buildid(&path).unwrap().unwrap(); | ||
// ground truth obtained from GNU binutils's readelf | ||
assert_eq!( | ||
buildid, | ||
b"\xf9\xc0\xc6\x05\xd3\x76\xbb\xa5\x7e\x02\xf5\x74\x50\x9d\x16\xcc\xe9\x9c\x1b\xf1" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#![cfg(feature = "read")] | ||
|
||
mod coff; | ||
mod elf; |