There were 2 problems in this case. Imagine that anount of input sections
is incorrect and huge (> UINT32_MAX). Lets say it is x = UINT32_MAX + 1;
- On 64bit systems it just may crash with std::length_error when will try to allocate
more memory than is available.
- On 32bits situation is more interesting.
Sections.resize(Size);
will truncate Size to 0, so resize will work fine.
Next loop will never execute:
for (const Elf_Shdr &Sec : Obj.sections())
because Obj.sections() will return empty array because of implementation of:
template <class ELFT> const typename ELFFile<ELFT>::Elf_Shdr *ELFFile<ELFT>::section_end() const { return section_begin() + getNumSections(); }
And finally linkage can complete fine without errors. That is what I am observing with testcase.
I suggest to limit amount of input sections to some reasonable amount. Not sure what is better
UINT16_MAX or UINT32_MAX., patch uses first for now.