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; }