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

Handling Elf.ksy parsing exceptions #754

Closed
taviso opened this issue May 18, 2020 · 9 comments
Closed

Handling Elf.ksy parsing exceptions #754

taviso opened this issue May 18, 2020 · 9 comments

Comments

@taviso
Copy link

taviso commented May 18, 2020

Hello, I'm trying to integrate kaitai into my application, if I try to parse /bin/ls from Ubuntu 18.04 with Elf.ksy, I get an exception. I verified the same thing happens on the Web IDE.

I guess it's not clear to me if I should be handling this error, or if it's a bug?

To reproduce, load the attached binary (It's an original unmodified binary, you could also get it from here.

Then use the Web IDE to expand Elf.header.sectionHeaders[25].body.

The error is:

Parse error: undefined
Call stack: undefined KaitaiEOFError: requested 4832 bytes, but only 2104 bytes available

image

@taviso
Copy link
Author

taviso commented May 18, 2020

Oops, github rejected my attachment, lets try this instead.

sample.elf.gz

@GreyCat
Copy link
Member

GreyCat commented May 18, 2020

elf.ksy actually currently fails to compile at all now with this error:

elf.ksy:!:!: found duplicate key 1879048193

So I assume that you're using old ksc v0.8, which allows these duplicate keys.

In general, if it's a valid source ELF file (and it looks like it's a valid file), then any exception is an indicator of a problem in format specification. You should never get exceptions during parsing if the source file is valid.

So, I would start with:

  • Fixing duplicate key problem with elf.ksy
  • Retrying with latest ksc
  • Potentially, pinpointing and fixing a bug in elf.ksy related to the section that you've demonstrated, using file you've given

@generalmimon
Copy link
Member

@generalmimon
Copy link
Member

generalmimon commented Jul 6, 2020

To put it in perspective, the issue kaitai-io/kaitai_struct_formats#279 resolved the problem with duplicate keys, but I tested the sample.elf file using the latest revision of the executable/elf.ksy spec in https://ide.kaitai.io/devel/ and the problem after expanding Elf.header.sectionHeaders[25].body still persists.

@solemnwarning
Copy link

Just a heads up - the bunzip2 executable which is initially open in the web IDE has the same problem. You can see the error in the console, and when trying to export the header to JSON (which doesn't work).

@armijnhemel
Copy link

Looking at the screenshot: the section has type NOBITS meaning that there is no data associated with it and size doesn't describe actual file data.

@armijnhemel
Copy link

Also see kaitai-io/kaitai_struct_formats#517

@armijnhemel
Copy link

Should have been fixed now: kaitai-io/kaitai_struct_formats@4d74a6c

@generalmimon
Copy link
Member

Should have been fixed now: kaitai-io/kaitai_struct_formats@4d74a6c

I confirm that the sample.elf test file from #754 (comment) now works => closing.

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

No branches or pull requests

5 participants