Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic while trying to parse header #39

Open
terrarier2111 opened this issue Jan 27, 2023 · 5 comments
Open

Panic while trying to parse header #39

terrarier2111 opened this issue Jan 27, 2023 · 5 comments

Comments

@terrarier2111
Copy link

When trying to create a new ElfFile via ElfFile::new a panic occurs:
Bildschirmfoto vom 2023-01-27 10-46-55

@gz
Copy link
Owner

gz commented Jan 29, 2023

are you able to share the binary you're trying to load? Or minimal source example+compiler (version)+linker (version) that produces the binary?

@terrarier2111
Copy link
Author

this is the file renamed to .txt for upload but normally it has no file extension at all:
os-test.txt

@landhb
Copy link
Contributor

landhb commented Apr 17, 2023

I tried reproducing with the file above and it seems to work properly:

2023-04-17T17:17:01.168Z INFO  [repro] allocate base = 0x0 size = 0x219 flags =   R
2023-04-17T17:17:01.168Z INFO  [repro] allocate base = 0x1220 size = 0x22 flags = X R
2023-04-17T17:17:01.168Z INFO  [repro] allocate base = 0x2248 size = 0xa0 flags =  WR
2023-04-17T17:17:01.168Z INFO  [repro] load region into = 0x10000000 -- 0x10000219
2023-04-17T17:17:01.168Z INFO  [repro] load region into = 0x10001220 -- 0x10001242
2023-04-17T17:17:01.168Z INFO  [repro] load region into = 0x10002248 -- 0x100022e8

File loaded:

1a07577bc6bf37b0318dcf4919c35dda151c18c7 os-test.txt

Current crate versions:

elfloader v0.16.0 (rust-elfloader)
├── bitflags v1.3.2
├── log v0.4.14
│   └── cfg-if v1.0.0
└── xmas-elf v0.8.0
    └── zero v0.1.2

@ghost
Copy link

ghost commented Jul 8, 2023

I did run into the same issue when using include_bytes! to include the elf. when using e.g. fs::read it seems the resulting vec buffer is aligned to 0x10 so the alignment issue in zero doesnt happen. From a quick test

include_bytes'd elf @ 0x55d1ffa31a96
fs::read'd elf @ 0x7ff5c89b1010

Im not sure if this is even a bug but the alignment requirement of the slice should probably be documented if it isn't already and i just missed it

@landhb
Copy link
Contributor

landhb commented Jul 8, 2023

@maddiethecafebabe Thanks for the explanation. I created a PR to provide a proper error instead of panicking #41.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants