[PATCH] D43819: [ELF] - Restrict section offsets that exceeds file size.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 2 03:10:01 PST 2018


grimar added a comment.

In https://reviews.llvm.org/D43819#1023718, @jhenderson wrote:

> > Also, assuming the intended behaviour is that the section can start at the end of the file, if it is empty or NOBITS, I think the Overflow check is slightly wrong. If a NOBITS or empty section starts at the very end of the file (i.e. Sec->Offset == FileSize), it will be treated as overflowing as things stand.
>
> You've only addressed this comment for NOBITS sections and not empty sections. As things stand, an empty section at the very end of the file will cause an error. Similarly, any regular section that has a size such that it terminates at exactly the end of the file will have problems.


I am not sure I understand the use case, sorry. We normally can not have an empty section at the end of the file, because we place section header table there.
If somehow section offset is damaged during calculation because of overflows, then `((Sec->Offset >= FileSize) || (Sec->Offset + Sec->Size >= FileSize)` check will catch it and report an error to prevent
mapped buffer overflow and crash during writing. That is what this code supposed to do. What am I missing?


https://reviews.llvm.org/D43819





More information about the llvm-commits mailing list