From 43fde1a370cb5c0dd041ef1bc4f1ecf5bd874b35 Mon Sep 17 00:00:00 2001 From: Wang Jiajun Date: Thu, 21 Feb 2019 19:07:02 +0800 Subject: [PATCH] fix heap overflow --- .../predict-cpp/image-classification-predict.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/example/image-classification/predict-cpp/image-classification-predict.cc b/example/image-classification/predict-cpp/image-classification-predict.cc index 2a605b8b2674..3c72589399ba 100644 --- a/example/image-classification/predict-cpp/image-classification-predict.cc +++ b/example/image-classification/predict-cpp/image-classification-predict.cc @@ -76,7 +76,9 @@ class BufferFile { ifs.seekg(0, std::ios::beg); std::cout << file_path.c_str() << " ... " << length_ << " bytes\n"; - buffer_.reset(new char[length_]); + // Buffer as null terminated to be converted to string + buffer_.reset(new char[length_ + 1]); + buffer_[length_] = 0; ifs.read(buffer_.get(), length_); ifs.close(); }