Skip to content

Commit

Permalink
[jit][edge] Fix array index checking in mobile interpreter. (pytorch#…
Browse files Browse the repository at this point in the history
…73241)

Summary:
Pull Request resolved: pytorch#73241

Stop using non-portable out-of-range indexing in mobile interpreter, also change code types indexing to use vector.at() to catch out-of-range bugs earlier.

Test Plan: buck test mode/dbg mode/no-gpu -c fbcode.platform=platform010 //caffe2/test/cpp/jit:jit -- BackendTest.TestCompiler

Reviewed By: dhruvbird, r-barnes

Differential Revision: D34370237

fbshipit-source-id: 1827f75ed00ecc10bbcece48329b0ac87189b079
(cherry picked from commit ab943ef)
  • Loading branch information
zhxchen17 authored and pytorchmergebot committed Feb 24, 2022
1 parent 62eb7d6 commit cafd0f3
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions torch/csrc/jit/mobile/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ bool InterpreterState::run(Stack& stack) {
}
return false;
case LIST_CONSTRUCT: {
listConstruct(stack, *code.types_[inst.X], inst.N);
listConstruct(stack, *code.types_.at(inst.X), inst.N);
frame.step();
} break;
case LIST_UNPACK: {
Expand Down Expand Up @@ -305,21 +305,20 @@ bool InterpreterState::run(Stack& stack) {
frame.step();
} break;
case DICT_CONSTRUCT: {
dictConstruct(stack, *code.types_[inst.X], inst.N);
dictConstruct(stack, *code.types_.at(inst.X), inst.N);
frame.step();
} break;
case NAMED_TUPLE_CONSTRUCT: {
namedTupleConstruct(stack, code.types_[inst.X], inst.N);
namedTupleConstruct(stack, code.types_.at(inst.X), inst.N);
frame.step();
} break;
case CREATE_OBJECT: {
auto type = code.types_[inst.X]->expect<c10::ClassType>();
auto type = code.types_.at(inst.X)->expect<c10::ClassType>();
createObject(stack, type);
frame.step();
} break;
case ISINSTANCE: {
at::ArrayRef<TypePtr> types(
&(code.types_[inst.X]), &(code.types_[inst.X + inst.N]));
at::ArrayRef<TypePtr> types(&code.types_.at(inst.X), inst.N);
isinstance(stack, types);
frame.step();
} break;
Expand Down

0 comments on commit cafd0f3

Please sign in to comment.