Skip to content

Commit

Permalink
linux: larger artifact support (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
drahnr authored Nov 19, 2024
1 parent f241ef3 commit 31fd373
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
[package]
name = "libsui"
version = "0.5.0"
version = "0.6.0"
authors = ["the Deno authors"]
edition = "2021"
license = "MIT"
Expand Down
14 changes: 8 additions & 6 deletions lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,11 @@ impl<'a> Elf<'a> {

// hash the name to 4 bytes int
const MAGIC: u32 = 0x501e;
const TRAILER_LEN: u64 = 8 + 4 + 4;

elf.extend_from_slice(&MAGIC.to_le_bytes());
elf.extend_from_slice(&hash(name).to_le_bytes());
elf.extend_from_slice(&(sectdata.len() as u32 + 12).to_le_bytes());
elf.extend_from_slice(&(sectdata.len() as u64 + TRAILER_LEN).to_le_bytes());

writer.write_all(&elf)?;
Ok(())
Expand All @@ -752,8 +753,9 @@ mod elf {
return None;
};

file.seek(SeekFrom::End(-12)).unwrap();
let mut buf = [0; 12];
const TRAILER_LEN: i64 = 8 + 4 + 4;
file.seek(SeekFrom::End(-TRAILER_LEN)).unwrap();
let mut buf = [0; TRAILER_LEN as usize];
file.read_exact(&mut buf).unwrap();
let magic = u32::from_le_bytes([buf[0], buf[1], buf[2], buf[3]]);
if magic != 0x501e {
Expand All @@ -766,15 +768,15 @@ mod elf {
return None;
}

let offset = u32::from_le_bytes([buf[8], buf[9], buf[10], buf[11]]) as u64;
let offset = u64::from_le_bytes([buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]]) as i64;

file.seek(SeekFrom::End(-(offset as i64))).unwrap();
file.seek(SeekFrom::End(-offset)).unwrap();

// Read section data
let mut buf = Vec::new();
file.read_to_end(&mut buf).unwrap();

let data = buf[..buf.len() - 12].to_vec();
let data = buf[..buf.len() - TRAILER_LEN as usize].to_vec();

Some(Box::leak(data.into_boxed_slice()))
}
Expand Down
1 change: 1 addition & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ fn test_macho(size: usize, sign: bool) {
let mut out = std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.mode(0o755)
.open(&_path)
.unwrap();
Expand Down

0 comments on commit 31fd373

Please sign in to comment.