-
Notifications
You must be signed in to change notification settings - Fork 159
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
Crash on malformed ELF file #120
Comments
Many parts of the parser rely on the binary giving lengths to various variable length entities; I guess the best we can do here is to clamp the maximum size to the size of the binary? |
Sounds like a great idea! Alternatively you could let the API user set the limits, which is what the decompression libraries do. But if you know the size up front, it's probably best to just use that. |
@Shnatsel do you want to make a PR :) |
It would be interesting, but I'm afraid I'll have to decline. I already have two ongoing Rust projects that have higher priority, and one of them isn't even announced yet. |
In general, how does goblin want to handle errors: parse as much as it can, or return an error immediately when something is obviously wrong? For example, if the size of a section is larger than the size of the file, should it still try to parse whatever it can in that section? Or should it skip that section but keep trying to parse other sections? Or should it immediately return an error? I can have a look at some of these. However, not all of them are giving errors for me.
gives:
|
These are all good questions, and I'm not sure what the best answer is; I think we've tried to be as robust as possible in the past, but it starts getting into a grey area; overall however, I've found it almost always better for the parser to just keep going even when stuff is kind of broken, as opposed to just returning immediately and stopping all parsing, since that forces you to dive into a hexdump or some other tool if you want more details and the error message isn't super useful. |
For my purposes, I think what I want is for goblin to provide lower level APIs that parse one thing, and return an error if that fails. It's then up to me to decide whether I want to continue trying to parse other things. goblin doesn't currently provide that sort of lower level API though. It tries to parse everything into a struct |
Fixed what I could in #121. There's probably more similar problems. Not something I'm going to work on right now though. |
Representative test cases for the problems I fixed:
|
Looks reasonable to me, but I'll let @m4b review. Really need to audit every |
Attempting to decode any of the attached files with
goblin::elf::Elf::parse
crashes the process. Memory allocator runs out of virtual memory and the process is aborted.goblin-elf-oom-crashes.zip
Found via AFL.rs. Fuzzing harness: https://github.com/Shnatsel/goblin/blob/master/fuzz-afl/src/main.rs
The text was updated successfully, but these errors were encountered: