This is an archive of the discontinued LLVM Phabricator instance.

Avoid a UB pointer overflow in the ArrayRef unit test
ClosedPublic

Authored by vsk on May 12 2017, 1:08 PM.

Details

Summary

The intent of the test is to check that array lengths greater than
UINT_MAX work properly. Change the test to stress that scenario, without
triggering pointer overflow UB.

Caught by a WIP pointer overflow checker in clang.

Diff Detail

Repository
rL LLVM

Event Timeline

vsk created this revision.May 12 2017, 1:08 PM
ab edited edge metadata.May 15 2017, 9:38 AM

Huh, interesting.. Not a big deal, but can you avoid the #ifdef? Where was the overflow?

vsk added a comment.May 15 2017, 9:47 AM
In D33149#755166, @ab wrote:

Huh, interesting.. Not a big deal, but can you avoid the #ifdef? Where was the overflow?

The overflow occurred in drop_front etc. The start of the array moved from 0x10000 to 2^64 - 2.

I think these tests need to add UINT_MAX or greater to a pointer to check that size_t-sized lengths work. For 32-bit machines, I don't think there's a way to add such a large offset to a pointer and not overflow.

vsk added a comment.May 31 2017, 11:49 AM

@ab Ping, would you be ok with leaving the ifdef in?

vsk added a comment.May 31 2017, 2:39 PM

Ahmed and I chatted about this. We discussed an alternative to this patch, which is to test with a length of max<ptroff_t>. This version of the test wouldn't require any ifdefs, and would still add some coverage for r271546.

This revision was automatically updated to reflect the committed changes.