-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add support to read zlib compressed files, like vmlinux.gz #103
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not particularly happy on how this is implemented. Let me elaborate:
-
The magic number comparison could be in a separate function, either a static function in ElfObject class or a auxiliary function in NonLLVMMisc.cpp. Maybe even creating a separate class for this and return an
enum
with all known magic numbers. -
Be careful to initialize the file buffers correctly.
read
can fail in many ways, such as simple as it not being able to read the file because of permission errors. -
"Guessing" the deflated file size without any kind of fail mechanism is very dangerous. You should do it in a loop and call
realloc
if things go south. -
Make sure the provided library doesn't provide a way of stream-decompress the file without preloading the file on memory by yourself. This is usually much faster on today machines because of asynchronous disk operations: disk access is slow, CPU is blazing fast.
b19cba8
to
22ac2dc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are minor things that needs to be solved.
|
||
Elf *elf = elf_memory((char *)dest, ret); | ||
if (elf == nullptr) { | ||
free(dest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
close(ElfFd)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case the fd will leak. Once you decompressed the file you do not need the File Descriptor anymore. Furthermore, this function is called in ElfObject constructor. If this throws, then the destructor will not be called!
22ac2dc
to
f57a78f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PLease fix the last file descriptor leak
{ | ||
|
||
unsigned char buf[4] = { 0 }; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the file descriptor is not in the beginning of file, this will fail.
|
||
Elf *elf = elf_memory((char *)dest, ret); | ||
if (elf == nullptr) { | ||
free(dest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case the fd will leak. Once you decompressed the file you do not need the File Descriptor anymore. Furthermore, this function is called in ElfObject constructor. If this throws, then the destructor will not be called!
This class will contain a static method to detect which file we are dealing with w.r.t ELF files. Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
f57a78f
to
16a68ce
Compare
This is useful for decompressing vmlinux files and kernel modules compressed using zlib/gzip. Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
16a68ce
to
219aef6
Compare
This is useful for decompressing vmlinux files and kernel modules compressed using zlib/gzip.