[PATCH] D25279: [ELF] - Do not crash on large output.

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 6 14:17:37 PDT 2016


On 6 October 2016 at 17:02, George Rimar <grimar at accesssoftek.com> wrote:
> grimar added inline comments.
>
>
>> rafael wrote in Writer.cpp:1223
>> I wonder how many cases there can be where overflow and if there is a general solution.
>>
>> How was this crashing before?
>
> Yes, that is a problem, solution is not general :( Crash was because of overflow of Off that is used to calculate FileSize.
> So file created was little and it then crashes in writeTo during writing output sections.
> We do not check end of buffer there. Probably it can be a that "general solution". I`ll try to do domething tomorrow with that.


OK, it seems that from a "just don't crash" point of view the two
options are avoiding overflow when computing the size or checking
offsets when writing. Avoiding overflow sounds better.

I guess a template class that wraps an integer, checks for overflow on
add/sub would not be too cumbersome to add to the hopefully few places
that actually lead to crashes.

For example, assuming that

return First->getFileOffset() + Sec->getVA() - First->getVA();

can overflow, we could just write something like

return makeChecked(First->getFileOffset()) + Sec->getVA() - First->getVA();

Cheers,
Rafael


More information about the llvm-commits mailing list