From: David Riazati Date: Tue, 2 Apr 2019 00:31:53 +0000 (-0700) Subject: Fix uninitialized value in pickler (#18678) X-Git-Tag: accepted/tizen/6.5/unified/20211028.231830~493 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8e873ce273c17cfc45f3c24043474e1b62222bb1;p=platform%2Fupstream%2Fpytorch.git Fix uninitialized value in pickler (#18678) Summary: Fixes #18671 Pull Request resolved: https://github.com/pytorch/pytorch/pull/18678 Differential Revision: D14708969 Pulled By: driazati fbshipit-source-id: d372c6e3a2a3d3fc48d8afc1fa6807f2ce0e5c6e --- diff --git a/torch/csrc/jit/pickler.cpp b/torch/csrc/jit/pickler.cpp index df95bc4..3da6b7e 100644 --- a/torch/csrc/jit/pickler.cpp +++ b/torch/csrc/jit/pickler.cpp @@ -338,8 +338,15 @@ OpCode Unpickler::readInstruction() { // Look back to see if the last opcode was an IntList class if (last_opcode_ == OpCode::NEWOBJ) { // It's a list specialization, the enum ID of which is on the stack - PicklerClass cls = - static_cast(uint8_t(stack_.back().toInt())); + AT_CHECK( + stack_.size() > 0, + "Unpickler found an empty stack when it expected a value"); + auto value = stack_.back().toInt(); + AT_CHECK( + value >= 0 && value <= std::numeric_limits::max(), + "Unpickler could not decode PicklerClass for ", + value); + PicklerClass cls = static_cast(uint8_t(value)); if (cls == PicklerClass::INTLIST) { stack_.emplace_back(std::vector()); } diff --git a/torch/csrc/jit/pickler.h b/torch/csrc/jit/pickler.h index ab35a70..22061c9 100644 --- a/torch/csrc/jit/pickler.h +++ b/torch/csrc/jit/pickler.h @@ -150,7 +150,8 @@ class Unpickler { const std::vector* tensor_table) : bytes_(static_cast(data)), end_ptr_(bytes_ + size), - tensor_table_(tensor_table) {} + tensor_table_(tensor_table), + last_opcode_(OpCode::STOP) {} std::vector parse_ivalue_list();