From caed8507f45e637658104bdb3790f3c74035bd1d Mon Sep 17 00:00:00 2001 From: Guenter Obiltschnig Date: Mon, 26 Sep 2016 18:20:32 +0200 Subject: [PATCH] fixed issues reported by Klocwork --- Zip/src/ZipFileInfo.cpp | 18 ++++++++++++------ Zip/src/ZipLocalFileHeader.cpp | 18 ++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Zip/src/ZipFileInfo.cpp b/Zip/src/ZipFileInfo.cpp index 4adedac3f..62e14cf5b 100644 --- a/Zip/src/ZipFileInfo.cpp +++ b/Zip/src/ZipFileInfo.cpp @@ -98,15 +98,21 @@ void ZipFileInfo::parse(std::istream& inp, bool assumeHeaderRead) _uncompressedSize = getUncompressedSizeFromHeader(); parseDateTime(); Poco::UInt16 len = getFileNameLength(); - Poco::Buffer buf(len); - inp.read(buf.begin(), len); - _fileName = std::string(buf.begin(), len); + if (len > 0) + { + Poco::Buffer buf(len); + inp.read(buf.begin(), len); + _fileName = std::string(buf.begin(), len); + } if (hasExtraField()) { len = getExtraFieldLength(); - Poco::Buffer xtra(len); - inp.read(xtra.begin(), len); - _extraField = std::string(xtra.begin(), len); + if (len > 0) + { + Poco::Buffer xtra(len); + inp.read(xtra.begin(), len); + _extraField = std::string(xtra.begin(), len); + } } len = getFileCommentLength(); if (len > 0) diff --git a/Zip/src/ZipLocalFileHeader.cpp b/Zip/src/ZipLocalFileHeader.cpp index ec4465ddc..645775767 100644 --- a/Zip/src/ZipLocalFileHeader.cpp +++ b/Zip/src/ZipLocalFileHeader.cpp @@ -117,15 +117,21 @@ void ZipLocalFileHeader::parse(std::istream& inp, bool assumeHeaderRead) throw Poco::DataFormatException("bad ZIP file header", "invalid compression method"); parseDateTime(); Poco::UInt16 len = getFileNameLength(); - Poco::Buffer buf(len); - inp.read(buf.begin(), len); - _fileName = std::string(buf.begin(), len); + if (len > 0) + { + Poco::Buffer buf(len); + inp.read(buf.begin(), len); + _fileName = std::string(buf.begin(), len); + } if (hasExtraField()) { len = getExtraFieldLength(); - Poco::Buffer xtra(len); - inp.read(xtra.begin(), len); - _extraField = std::string(xtra.begin(), len); + if (len > 0) + { + Poco::Buffer xtra(len); + inp.read(xtra.begin(), len); + _extraField = std::string(xtra.begin(), len); + } } if (!searchCRCAndSizesAfterData()) {