-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the behavior of vector<bool, HugeAlloc>
whose size overflows uint32_t
#3342
Fix the behavior of vector<bool, HugeAlloc>
whose size overflows uint32_t
#3342
Conversation
Such usage seems reasonable for 32-bit platforms.
And avoid duplicating _VBITS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I certainly like the bugfix here; however, I'm not sure I love that we have this new _VBITS_DIFF
; it doesn't seem that unreasonable to just cast _VBITS
to difference_type
in the specific places it's required. I'm still an approve, though.
|
||
void test_huge_vector_bool() { | ||
constexpr uint64_t small_bit_length = 0x7000'4321ULL; | ||
constexpr uint64_t large_bit_length = 0x1'2000'4321ULL; // overflows uint32_t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am somewhat concerned about the test reliability implications of consuming 604 MB at runtime. That said, this is less than the compiler memory consumption of certain ranges tests, so I have no concrete objection to this.
@@ -2393,7 +2395,7 @@ public: | |||
|
|||
#if _ITERATOR_DEBUG_LEVEL != 0 | |||
_CONSTEXPR20 _Difference_type _Total_off(const _Mycont* _Cont) const noexcept { | |||
return static_cast<_Difference_type>(_VBITS * (_Myptr - _Cont->_Myvec.data()) + _Myoff); | |||
return static_cast<_Difference_type>(_VBITS_DIFF * (_Myptr - _Cont->_Myvec.data()) + _Myoff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No change requested: I searched for all mentions of _VBITS
and it appears that all affected locations are indeed being updated. 😻
Thanks! I fixed a comment typo and rewrapped it, and changed the test allocator's converting constructor to take a const reference as is traditional. |
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
5 billion thanks for fixing this bug! 😹 🐞 🛠️ |
On 32-bit platforms, the following program currently behaves incorrectly with MSVC STL - assertions fail (but pass on 64-bit platforms). Godbolt link.
The cause of this issue is that multiplication of
_VBITS
(of typeint
after lvalue-to-rvalue conversion) and differences of pointers (of typeptrdiff_t
) may overflowint32_t
. IMO it's still reasonable for a 32-bit program to allocate ~600MiB storage for a dynamic bitset, so this issue probably needs fix.This PR casts
_VBITS
todifference_type
/_Difference_type
(which isint64_t
when usinghuge_allocator
) before multiplication in order to fix the issue.