From 1ef472df680bf8bde493942f2f02b2643e50fac1 Mon Sep 17 00:00:00 2001 From: lucylq Date: Mon, 21 Jul 2025 17:08:41 -0700 Subject: [PATCH] Out-of-bounds accesses in operator execution ^ Test on top of D78676341 Differential Revision: [D78702540](https://our.internmc.facebook.com/intern/diff/D78702540/) [ghstack-poisoned] --- kernels/prim_ops/et_copy_index.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kernels/prim_ops/et_copy_index.cpp b/kernels/prim_ops/et_copy_index.cpp index 8ba79165729..97a5d5bb264 100644 --- a/kernels/prim_ops/et_copy_index.cpp +++ b/kernels/prim_ops/et_copy_index.cpp @@ -68,6 +68,18 @@ void et_copy_index(KernelRuntimeContext& context, EValue** stack) { (void)context; SizesType expected_output_size[kTensorDimensionLimit]; + // Verify that the arguments exist with the expected types. + ET_CHECK_MSG(stack != nullptr, "Stack pointer is null."); + ET_CHECK_MSG( + stack[0] != nullptr && (*stack[0]).isTensor(), + "copy_to is null, or not a tensor."); + ET_CHECK_MSG( + stack[1] != nullptr && (*stack[1]).isTensor(), + "copy_from is null, or not a tensor."); + ET_CHECK_MSG( + stack[2] != nullptr && (*stack[2]).isInt(), + "index is null, or not an integer."); + auto copy_to = (*stack[0]).toTensor(); auto copy_from = (*stack[1]).toTensor(); auto index = (*stack[2]).toInt();