Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add size check before calling stack_.at(dict_pos) in unpickler.cpp #94300

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions torch/csrc/jit/serialization/unpickler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,20 @@ PickleOpCode Unpickler::readInstruction() {
// | Dict | -> (stack_size - 3)
// | Key | -> (stack_size - 2)
// | Value | -> (stack_size - 1)
TORCH_CHECK(
stack_.size() >= 3,
"Parsing error: stack doesn't have enough elements");

auto stack_size = stack_.size();
auto dict_pos = stack_size - 3;
auto key_pos = stack_size - 2;
auto val_pos = stack_size - 1;

TORCH_CHECK(
(dict_pos < stack_size) && (key_pos < stack_size) &&
(val_pos < stack_size),
"Parsing error: attempted out-of-bounds access while processing SETITEM opcode");

auto dict = stack_.at(dict_pos).toGenericDict();
dict.insert_or_assign(stack_.at(key_pos), stack_.at(val_pos));
stack_.erase(stack_.begin() + (key_pos), stack_.end());
Expand Down