Skip to content
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

[BUG]: thrust::zip_iterator allows out-of-bounds access if first iterator is longer than the others #1155

Open
1 task done
Jacobfaib opened this issue Nov 28, 2023 · 1 comment
Assignees
Labels
bug Something isn't working right. needs triage Issues that require the team's attention

Comments

@Jacobfaib
Copy link
Contributor

Is this a duplicate?

Type of Bug

Runtime Error

Component

Thrust

Describe the bug

Out of bounds access when the first iterator in a zip_iterator is longer than the others

How to Reproduce

// clang++ -I/path/to/thrust thrust_bug.cpp -o thrust_bug && ./thrust_bug
#include <thrust/iterator/zip_iterator.h>
#include <thrust/tuple.h>

#include <vector>
#include <iostream>

int main()
{
  std::vector<int> v(4, 0); // change me to 5!
  std::vector<int> y(4, 1);

  auto zip_begin = thrust::make_zip_iterator(thrust::make_tuple(v.begin(), y.begin()));
  auto zip_end   = thrust::make_zip_iterator(thrust::make_tuple(v.end(), y.end()));

  for (auto it = zip_begin; it != zip_end; ++it) {
    // BOOM out of bounds
    std::cout << "[" << thrust::get<0>(*it) << ", " << thrust::get<1>(*it) << "]" << std::endl; 
  }
}

Note the size of v and y are equal. If, however, you change v to be size 5

-   std::vector<int> v(4, 0);
+   std::vector<int> v(5, 0);

You will find that the iterator runs out of bounds.

Expected behavior

No out of bounds

Reproduction link

No response

Operating System

No response

nvidia-smi output

No response

NVCC version

No response

@Jacobfaib Jacobfaib added the bug Something isn't working right. label Nov 28, 2023
@github-project-automation github-project-automation bot moved this to Todo in CCCL Nov 28, 2023
@github-actions github-actions bot added the needs triage Issues that require the team's attention label Nov 28, 2023
Copy link
Contributor

Hi @Jacobfaib!

Thanks for submitting this issue - the CCCL team has been notified and we'll get back to you as soon as we can!
In the mean time, feel free to add any relevant information to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right. needs triage Issues that require the team's attention
Projects
Status: Todo
Development

No branches or pull requests

2 participants