m4b / goblin

An impish, cross-platform binary parsing crate, written in Rust
MIT License
1.17k stars 156 forks source link

Parsing fails when the TLS index is in the zeroed area of a section #411

Open gabrielesvelto opened 1 month ago

gabrielesvelto commented 1 month ago

While processing DLLs from NVidia's graphics drivers I stumbled upon this file which failed to parse correctly. What happens at the point of error is the following:

The expected behavior of this particular code should be that the TLS index is simply set to zero, since the address points to an area of memory which is set to zero.

This seems to make sense from a logical perspective, given that Microsoft documentations mentions that this area is populated by the loader, so the section won't contain the actual value until it's loaded. It thus makes sense for it to be in a zeroed area.

gabrielesvelto commented 1 month ago

I wonder if this might be a potential issue in more areas of the code. utils::find_offset() will always fail if the offset falls within a section, but not within the area populated in the file, however those offsets aren't invalid, they will be once the module is loaded into memory. It's just that they'll point to data that contain zeroes.