Skip to content

Commit 75530a3

Browse files
author
Github Executorch
committed
Update on "Use safe_numel() in et"
The wasm bindings' assert_valid_numel() helper previously computed numel without overflow detection, letting a malicious tensor shape wrap to a small value that bypassed the data-size check. Replace with safe_numel() (returns Result<ssize_t>) and propagate the error via THROW_IF_ERROR as a JavaScript exception, matching the rest of the wasm error plumbing. Authored with Claude. Differential Revision: [D102082911](https://our.internmc.facebook.com/intern/diff/D102082911/) [ghstack-poisoned]
2 parents cdc7150 + 64ccf01 commit 75530a3

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

runtime/core/exec_aten/exec_aten.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ inline ssize_t compute_numel(const SizesType* sizes, ssize_t dim) {
114114
c10::multiply_integers(c10::ArrayRef<SizesType>(sizes, dim)));
115115
}
116116

117-
ET_EXPERIMENTAL inline ::executorch::runtime::Result<ssize_t> safe_numel(
117+
inline ::executorch::runtime::Result<ssize_t> safe_numel(
118118
const SizesType* sizes,
119119
ssize_t dim) {
120120
ET_CHECK_OR_RETURN_ERROR(

runtime/core/portable_type/tensor_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,12 @@ ssize_t compute_numel(
296296
ssize_t dim);
297297

298298
/**
299-
* EXPERIMENTAL. Compute the number of elements based on the sizes of a tensor.
299+
* Compute the number of elements based on the sizes of a tensor.
300300
* Returns Error::InvalidArgument if any intermediate multiplication would
301301
* overflow ssize_t, or if a size is negative. Prefer this over compute_numel()
302302
* for paths that can propagate an Error upward.
303303
*/
304-
ET_EXPERIMENTAL ::executorch::runtime::Result<ssize_t> safe_numel(
304+
::executorch::runtime::Result<ssize_t> safe_numel(
305305
const ::executorch::runtime::etensor::TensorImpl::SizesType* sizes,
306306
ssize_t dim);
307307

0 commit comments

Comments
 (0)