Fix write-heap-buffer-overflow in et_copy_index #15782
Open
+48
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
--> index < size check happens after potential tensor resize
The crash is a write-heap-buffer-overflow that occurs in the
et_copy_indexfunction. The root cause is the lack of proper validation of theindexargument, which can lead to an out-of-bounds write whenindexis negative or exceeds the bounds of thecopy_totensor.The patch fixes the crash by adding two checks:
ET_CHECK_MSG(index >= 0, "Index must be non-negative");andET_CHECK_MSG(index < copy_to.sizes()[0], "Index out of bounds");. These checks ensure thatindexis within the valid range for thecopy_totensor, preventing the out-of-bounds write.Other considerations that reviewers should take into account when validating the patch include verifying that the added checks do not introduce any performance regressions and that they correctly handle edge cases, such as when
indexis equal tocopy_to.sizes()[0] - 1. Reviewers should also check that the patch does not alter the existing functionality of theet_copy_indexfunction and that it is consistent with the surrounding code.Additionally, reviewers may want to consider testing the patch with various inputs, including negative
indexvalues,indexvalues that exceed the bounds ofcopy_to, and validindexvalues, to ensure that the patch correctly prevents the write-heap-buffer-overflow crash.Here is the commit message:
These checks ensure that
indexis within the valid range for thecopy_totensor, preventing the out-of-bounds write.Other considerations that reviewers should take into account when validating the patch include verifying that the added checks do not introduce any performance regressions and that they correctly handle edge cases, such as when
indexis equal tocopy_to.sizes()[0] - 1. Reviewers should also check that the patch does not alter the existing functionality of theet_copy_indexfunction and that it is consistent with the surrounding code.