diff --git a/torch/csrc/jit/mobile/interpreter.cpp b/torch/csrc/jit/mobile/interpreter.cpp index 2d112034971..5fa90dbecdb 100644 --- a/torch/csrc/jit/mobile/interpreter.cpp +++ b/torch/csrc/jit/mobile/interpreter.cpp @@ -159,6 +159,15 @@ bool InterpreterState::run(Stack& stack) { static_cast(inst.X) >= code.constants_.size()) { TORCH_CHECK(false, "Can't load constant with index: ", inst.X); } + if (inst.N == 0 || inst.N > stack.size()) { + TORCH_CHECK( + false, + "INTERFACE_CALL N=", + inst.N, + " not in range [1, ", + stack.size(), + "]"); + } torch::jit::Function& method = peek(stack, 0, inst.N) .toObject()