From d471eaeb1d2fbc7efcde6408d7d1e513b969af25 Mon Sep 17 00:00:00 2001 From: Shiyan Deng Date: Wed, 6 Sep 2023 00:02:42 +0000 Subject: [PATCH] fix inline_container.cc inplace loading (#108573) Summary: bypass-github-pytorch-ci-checks bypass-github-export-checks force-merge-on-github Differential Revision: D48971847 Pull Request resolved: https://github.com/pytorch/pytorch/pull/108573 Approved by: https://github.com/wqfish --- caffe2/serialize/inline_container.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/caffe2/serialize/inline_container.cc b/caffe2/serialize/inline_container.cc index 1cff38df693b..1581ecd33582 100644 --- a/caffe2/serialize/inline_container.cc +++ b/caffe2/serialize/inline_container.cc @@ -368,7 +368,11 @@ size_t PyTorchStreamReader::getRecord( iter != nullptr, "Failed to create zip reader iter: ", mz_zip_get_error_string(mz_zip_get_last_error(ar_.get()))); - + std::vector buffer; + if (buf == nullptr) { + buffer.resize(chunk_size); + buf = buffer.data(); + } for (size_t offset = 0; offset < stat.m_uncomp_size; offset += chunk_size) { size_t want_size = std::min(chunk_size, (size_t)stat.m_uncomp_size - offset);