patchelf icon indicating copy to clipboard operation
patchelf copied to clipboard

possibly too large new section header created

Open DerDakon opened this issue 5 years ago • 1 comments

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.

DerDakon avatar Sep 04 '20 09:09 DerDakon

It would be great to have a test case for this.

domenkozar avatar Aug 09 '21 11:08 domenkozar