-
-
Notifications
You must be signed in to change notification settings - Fork 5.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
Constructing a 67108864 TiB array succeeds incorrectly, corrupting memory #54328
Comments
That's suboptimal. We probably need one more checked mul on the C side. |
hmm, we already are doing the multiplication with wide arithmetic: Line 42 in c88f4e2
wideint_t somehow being set to uint64?
|
What does "UB" mean here (the UB bug really bit people...). This is just a bug. |
That is how Lines 19 to 23 in e637be1
|
UINT128MAX seems to never exist. What is that supposed to be? |
It is possible to throw if |
Ideally we don't need division there, as that is much slower than checking for multiplication overflow |
Apparently there is no standards-defined way to avoid this UB in C for multiply. But most compilers have extensions (specifically |
Could we move the checking into Julia? Seems we can do this more reliably than C. |
Moving the checks to Julia would be a bit dangerous in that anyoen that skips doing the checks could run into weird behavior, but if we give it a bad enough name, it's plausible that people won't try to use it... |
I mean that |
I think it is unlikely for this to result in incorrect results in user code. It is much more likely to result in crashes/segfaults, and it is also unlikely for a user to allocate an array of this size in the first place. |
pretty sure #55913 (at least mostly) fixes this by the way |
This isn't fixed as #55913 isn't merged. |
Introduced in e9be444: "Some work to make libjulia compilable on windows using the Intel compiler" Maybe we want: // works on gcc 4.6+; clang 3.3+; icc 16+, test with godbolt.org
#if defined(__SIZEOF_INT128__)
Just like what the Linux kernel does. |
The easier approach is to just use the builtin overflow intrinsics which are supported across all the major compilers. This is done as part of the |
Related, constructing an array of size 2^61 or 2^62 "works", but not 2^61-1 or 2^62-1:
I'm guessing all this is due to unchecked overflow when multiplying by
sizeof(eltype)
.Much if this behavior is also present on 1.10.
CC @oscardssmith who's been working on this recently.
All examples above are from nightly.
The text was updated successfully, but these errors were encountered: