Repository navigation
Fix write-heap-buffer-overflow in copy_out - #15784
Merged
Merged
Conversation
This was referenced Nov 12, 2025
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/15784
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New Failures, 2 Cancelled JobsAs of commit 5dcf5c6 with merge base e0dda90 ( NEW FAILURES - The following jobs have failed:
CANCELLED JOBS - The following jobs were cancelled. Please retry:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
manuelcandales
approved these changes
Nov 14, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
Check that out.nbytes() is at least as large as src.nbytes() to prevent copying beyond the range of src.
Also add a check on dtypes, make sure out and src dtypes are the same. Otherwise we may copy the wrong dtype without conversion.
The crash is a write-heap-buffer-overflow that occurs in the
torch::executor::native::copy_outfunction. The root cause is that thestd::memcpyoperation in this function does not check if the destination bufferoutis large enough to hold the data from the source tensorsrc. Specifically, the conditioninternal::sizes_match_ignoring_leading_1s(out.sizes(), src.sizes())checks if the sizes ofoutandsrcmatch, ignoring any leading dimensions of size 1 inout, but it does not guarantee thatout.nbytes()is greater than or equal tosrc.nbytes().The patch fixes the crash by adding an additional check
out.nbytes() >= src.nbytes()before performing thestd::memcpyoperation. This ensures that the destination bufferoutis large enough to hold the data fromsrc, preventing the buffer overflow.Other considerations that reviewers should take into account when validating the patch include verifying that the additional check does not introduce any performance regressions and that it correctly handles edge cases, such as when
srcis empty or whenoutandsrchave different data types. Reviewers should also check that the patch does not affect the functionality of thecopy_outfunction in other scenarios. Additionally, it is worth verifying that the fix is consistent with the existing error handling and checking mechanisms in thecopy_outfunction.NOTE: This diff is entirely auto-generated by LLM-based patch generator.
Reviewer should carefully examine this diff as Lionhead does not guarrantee the
correctnesss of the patch beyond fixing the crash and passing existing tests.
Please commandeer this diff and revise as needed. Our bot does not respond to
comments or revision requests (yet).
Differential Revision: D80885980