-
Notifications
You must be signed in to change notification settings - Fork 758
Bug in thrust::system::detail::sequential::copy_detail::copy for trivially copyable types #939
Comments
I strongly believe that the fix should be done in the
the information whether the iterators are valid or not is lost: since neither the As a consequence, I think #938 was the correct fix and should be reopened. Also, @griwes: you mentioned that there is a discussion for whether calling In a unit test that encounters this UB, we got the following crash:
At the time of writing, I have not thoroughly checked that this is related but I'm willing to bet it is. |
There is one or two different UBs that are happening here, depending on which side in the debate I mentioned you take:
Putting aside a problem that exists in all cases (that The reson why the fix both can and must be applied down the stack is that the calls above are 100% correct, it's the backend that introduces the illegal behavior, and only in the trivial case; and also it is trivial to check, by guarding the call to And also fixing it where the issue actually is, and not where it becomes apparent, fixes it also for all new code written against Thrust, where this exact issue would surface. |
Ok, I understand and agree that guarding against I found some references explaining how accessing However I still don't agree on the following: What is the case against dereferencing a null pointer being UB? The standard says:
Regarding memmove: whether C and C++ are good languages or are insane is irrelevant even though I agree. Moreover, this being UB is one aspect of the problem, the other one being that the GNU libc's |
Yes. Also please note that I don't believe the note on the issue is quite correct; the other issue being fixed doesn't fix this. Regarding null references: there's been a lot of discussion about whether And regarding your last paragraph, I think you interpreted what I said wrong (or maybe I wasn't clear enough): I see |
Resizing an empty vector resulted in dereferencing a past-the-end iterator in thrust::system::detail::sequential::copy_detail::copy. Add a guard check against this case. Fixes NVIDIA#939.
I believe this has been fixed. |
Errors reported by clangs UBSan on this example :
Output :
The text was updated successfully, but these errors were encountered: