Skip to content

Commit 31eea79

Browse files
lucylqfacebook-github-bot
authored andcommitted
Fix stack buffer overflow in get_view_as_real_copy_out_target_size
Summary: Check that self.dim() is smaller than kTensorDimensionLimit, otherwise we may write past the end of the out tensor. Differential Revision: D86356264
1 parent 6b545a2 commit 31eea79

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

kernels/portable/cpu/op_view_as_real_copy.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ Tensor& view_as_real_copy_out(
4141

4242
// Get the output shape
4343
Tensor::SizesType expected_output_size[kTensorDimensionLimit];
44+
ET_KERNEL_CHECK_MSG(
45+
ctx,
46+
self.dim() < kTensorDimensionLimit,
47+
InvalidArgument,
48+
out,
49+
"Output size buffer is too small. Expected at least %zu, got %zu",
50+
self.dim() + 1, kTensorDimensionLimit);
4451
get_view_as_real_copy_out_target_size(self, expected_output_size);
4552

4653
// Resize for dynamic shape

0 commit comments

Comments
 (0)