patchelf
patchelf copied to clipboard
possibly too large new section header created
Describe the bug
I'm looking at the code in rewriteSectionExecutable#906, which calculates the extra size needed to make the section header into a grown file. It does this:
off_t shSize = rdi(hdr->e_shoff) + rdi(hdr->e_shnum) * rdi(hdr->e_shentsize);
growFile(fileContents, fileContents->size() + shSize);
So, the new size is the current file size + the size of the section headers + the current offset of the section table. I would assume that the offset is of no interest and can be dropped here, so it would be reduced to:
off_t shSize = rdi(hdr->e_shnum) * rdi(hdr->e_shentsize);
growFile(fileContents, fileContents->size() + shSize);
I'm not sure if I don't get something subtle about the code flow here.
It would be great to have a test case for this.