From 7d130612a3a83463afb079d4ba7419a15cb757e5 Mon Sep 17 00:00:00 2001
From: Andrea Bulgarelli <bulgarelli@iasfbo.inaf.it>
Date: Wed, 16 Jul 2014 20:25:42 +0200
Subject: [PATCH] added exception generation if LZ4 decompression has problems

---
 src/ByteStream.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/ByteStream.cpp b/src/ByteStream.cpp
index 14615e6..95ab024 100644
--- a/src/ByteStream.cpp
+++ b/src/ByteStream.cpp
@@ -177,10 +177,14 @@ ByteStreamPtr PacketLib::ByteStream::decompress(enum CompressionAlgorithms algor
 			int buffsize = LZ4_decompress_safe((const char*)stream, (char*)tmpbuff, size(), dmax);
 			if(!buffsize)
 			{
-				cout << "LZ4 decompression error" << endl;
 				delete tmpbuff;
+				throw new PacketException("LZ4 decompression error");
 				return 0;
 			}
+			if(buffsize < 0) {
+				delete tmpbuff;
+				throw new PacketException("LZ4 decompression error: the source stream is malformed");
+			}
 			byte* decompbuff = new byte[buffsize];
 			memcpy(decompbuff, tmpbuff, buffsize);
 			b = ByteStreamPtr(new ByteStream(decompbuff, buffsize, bigendian));
-- 
GitLab