From 5668dbcccbd0d103b83788c0ffbd9f2147e9c9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Thu, 18 Apr 2019 17:37:34 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@783 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src_io_utils/pistreampacker.cpp | 11 ++++++++++- src_main/core/pibytearray.cpp | 14 +++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src_io_utils/pistreampacker.cpp b/src_io_utils/pistreampacker.cpp index 1d4d533d..60500cc0 100644 --- a/src_io_utils/pistreampacker.cpp +++ b/src_io_utils/pistreampacker.cpp @@ -141,12 +141,21 @@ void PIStreamPacker::received(const PIByteArray & data) { if (packet.size_s() == packet_size) { PIByteArray cd; if (crypt_frag) { + //piCout << "decrypt frags ..." << packet_size; while (packet.size_s() >= 4) { + //piCout << "decrypt frags take data ..."; PIByteArray frag; + //piCout << "decrypt frags take data done" << frag.size_s(); packet >> frag; + if (frag.isEmpty()) { + //piCout << "decrypt frags corrupt, break"; + cd.clear(); + break; + } cd.append(decryptData(frag)); - //piCout << "crypt_frag receive add frag" << frag.size_s(); + //piCout << "decrypt frags add" << frag.size_s(); } + //piCout << "decrypt frags done" << cd.size(); } else { cd = decryptData(packet); } diff --git a/src_main/core/pibytearray.cpp b/src_main/core/pibytearray.cpp index e7a6c489..3408d3ff 100755 --- a/src_main/core/pibytearray.cpp +++ b/src_main/core/pibytearray.cpp @@ -375,8 +375,14 @@ std::ostream &operator <<(std::ostream & s, const PIByteArray & ba) { PIByteArray & operator >>(PIByteArray & s, PIByteArray & v) { + if (s.size_s() < 4) { + s.clear(); + v.clear(); + return s; + } assert(s.size_s() >= 4); - int sz; s >> sz; + int sz = 0; + s >> sz; if (sz > s.size_s()) { piCout << "[PIByteArray] Warning: operator >> wants too much data, discard!"; s.clear(); @@ -384,7 +390,9 @@ PIByteArray & operator >>(PIByteArray & s, PIByteArray & v) { return s; } v.resize(sz); - if (sz > 0) memcpy(v.data(), s.data(), v.size()); - s.remove(0, v.size()); + if (sz > 0) { + memcpy(v.data(), s.data(), v.size()); + s.remove(0, v.size()); + } return s; }