[llm_patch] Fix out-of-bounds access in pad2d function
Stack from ghstack (oldest at bottom):
- -> #15832
https://github.com/pytorch/executorch/pull/15623
Add checks for pad1d and pad3d, as well as pad2d.
I think what happens is, we 'broadcast' the input tensor into the padded regions, depending on the pad algorithm (replication, reflection).
The pad algorithm takes an output tensor index, and returns an input tensor index. We need to check that this input tensor index is valid/within bounds.
The crash is a "wild-addr-read" that occurs in the pad2d function, which is part of the Executorch library. This type of crash typically indicates that the program is attempting to read from an invalid or uninitialized memory address.
The root cause of the crash is an out-of-bounds access in the pad2d function. The function uses a padding_ix function to calculate indices for the input tensor in, but it does not perform sufficient bounds checking to ensure that these indices are valid. As a result, the program may attempt to read from memory outside the bounds of the in tensor, leading to the crash.
The patch fixes the crash by adding bounds checking to the pad2d function. Specifically, it adds two ET_CHECK statements to verify that the indices calculated by padding_ix are within the valid range of the in tensor. The checks are performed using the following code: ET_CHECK(in_h_idx < in_height) and ET_CHECK(in_w_idx < in_width). By adding these checks, the patch ensures that the program will not attempt to read from invalid memory addresses, preventing the "wild-addr-read" crash.
Other considerations that reviewers should take into account when validating the patch include the potential impact on performance. The added ET_CHECK statements may introduce a small performance overhead, particularly if the pad2d function is called frequently. Reviewers should verify that the performance impact is acceptable and that the patch does not introduce any other unintended consequences. Additionally, reviewers should test the patch with a variety of input tensors and padding configurations to ensure that it correctly handles different edge cases. They should also verify that the ET_CHECK statements are triggered correctly when invalid indices are encountered, and that the program behaves as expected in these cases.
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: D80831697
:link: Helpful Links
:test_tube: See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/15832
- :page_facing_up: Preview Python docs built from this PR
Note: Links to docs will display an error until the docs builds have been completed.
:x: 6 New Failures, 2 Unrelated Failures
As of commit e3ec5332e6aeca47e0b8353f2953cc7e5a480639 with merge base b1e3e28bb611e06d484138be27221faffd89f565 ():
NEW FAILURES - The following jobs have failed:
-
Test CUDA Builds / test-model-cuda-e2e (openai, whisper-large-v3-turbo, non-quantized) / linux-job (gh)
RuntimeError: Command docker exec -t 965d46b359b80f0f153cd9b26ebaf952a2c3201e79200a57f4b590f695044e13 /exec failed with exit code 1 -
Test CUDA Builds / test-model-cuda-e2e (openai, whisper-large-v3-turbo, quantized-int4-tile-packed) / linux-job (gh)
RuntimeError: Command docker exec -t 9348325c95a7a849e68b1fd9fc28b4955486b55f4dc5d504e2a8f70b91454701 /exec failed with exit code 1 -
Test CUDA Builds / test-model-cuda-e2e (openai, whisper-large-v3-turbo, quantized-int4-weight-only) / linux-job (gh)
RuntimeError: Command docker exec -t e390e65788b1b5270f1845d1734dad196f39ac43a259449ce480dffef05be66e /exec failed with exit code 1 -
Test CUDA Builds / test-model-cuda-e2e (openai, whisper-small, non-quantized) / linux-job (gh)
RuntimeError: Command docker exec -t a9d09e509e8a037d228e43f2cd17b4ddcc2bcfe8be630fbaa70ae637d5349020 /exec failed with exit code 1 -
Test CUDA Builds / test-model-cuda-e2e (openai, whisper-small, quantized-int4-tile-packed) / linux-job (gh)
RuntimeError: Command docker exec -t 05b9abe5970a480ce3b15013f1cf529165947f039d63da736ac479c6e1a4eb62 /exec failed with exit code 1 -
Test CUDA Builds / test-model-cuda-e2e (openai, whisper-small, quantized-int4-weight-only) / linux-job (gh)
RuntimeError: Command docker exec -t b737a80440533c775451f638b8a022b9eb4e9de2997ef8fd48d93995616aea91 /exec failed with exit code 1
FLAKY - The following job failed but was likely due to flakiness present on trunk:
-
Test Metal Backend / test-model-metal-e2e (openai, whisper-small, non-quantized) / macos-job (gh) (similar failure)
RuntimeError: Command bash /Users/ec2-user/runner/_work/_temp/exec_script failed with exit code 1
BROKEN TRUNK - The following job failed but was present on the merge base:
👉 Rebase onto the `viable/strict` branch to avoid these failures
-
Test Metal Backend / test-model-metal-e2e (openai, whisper-large-v3-turbo, non-quantized) / macos-job (gh) (trunk failure)
RuntimeError: Command bash /Users/ec2-user/runner/_work/_temp/exec_script failed with exit code 1
This comment was automatically generated by Dr. CI and updates every 15 minutes.
This PR needs a release notes: label
If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.
To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"
For more information, see https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.