[COFF] Don't reject executables with data directories pointing outside of provided...
authorMartin Storsjö <martin@martin.st>
Wed, 8 Jun 2022 20:55:45 +0000 (23:55 +0300)
committerMartin Storsjö <martin@martin.st>
Wed, 15 Jun 2022 13:51:20 +0000 (16:51 +0300)
commitb209b9e11c265e52f5897b2e014aa6933eb26703
tree2e0c118e27f58a02d92b47e377058dc8ffe36135
parentc60c13f7eb7157de1986c0da955d8ba856b65e07
[COFF] Don't reject executables with data directories pointing outside of provided data

Before bb94611d6545c2c5271f5bb01de1aa4228a37250, we didn't check
that the sections in the COFF executable actually contained enough
raw data, when looking up what section contains tables pointed to
by the data directories.

That commit added checking, to avoid setting a pointer that points
out of bounds - by rejecting such executables.

It turns out that some binaries (e.g.g a "helper.exe" provided by
NSIS) contains a base relocation table data directory that points
into the wrong section. It points inside the virtual address space
allocated for that section, but the section contains much less raw
data, and the table points outside of the provided raw data.

No longer reject such binaries (to let tools operate on them and
inspect them), but don't set the table pointers (so that when
printing e.g. base relocations, we don't print anything).

This should fix the regression pointed out in
https://reviews.llvm.org/D126898#3565834.

Differential Revision: https://reviews.llvm.org/D127345
llvm/lib/Object/COFFObjectFile.cpp
llvm/test/Object/Inputs/COFF/data-dir-out-of-bounds.yaml [new file with mode: 0644]
llvm/test/Object/coff-data-dir-out-of-bounds.test [new file with mode: 0644]