ReFirmLabs / binwalk

Firmware Analysis Tool
MIT License
10.54k stars 1.51k forks source link

Extraction path incorrect when binwalk runs in root directory #576

Open AndrewFasano opened 2 years ago

AndrewFasano commented 2 years ago

If you run binwalk from the root directory the logic in https://github.com/ReFirmLabs/binwalk/blob/master/src/binwalk/modules/extractor.py#L557-L560 goes wrong because self.directory='/' which leads to the split path returning a list where the first item is an empty string.

For example, if you try to extract /input/data, the script calculates subdir to be /nput/data which is incorrect and will cause an error later when it tries to make the directory /nput/data unless the directory /nput happens to exist.

I encountered this issue when running binwalk in a container, I understand that running it from the root directory is probably not a common use case.