From 55ab41613e4b4df8faf17afd5dda28fe73faa7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Mon, 29 Nov 2021 15:38:56 +0100 Subject: [PATCH] Update inflate/deflate with right flag (Z_FINISH, no Z_SYNC_FLUSH) --- utils/drmprocessorclientimpl.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/utils/drmprocessorclientimpl.cpp b/utils/drmprocessorclientimpl.cpp index 3a17763..9c5ec1e 100644 --- a/utils/drmprocessorclientimpl.cpp +++ b/utils/drmprocessorclientimpl.cpp @@ -444,7 +444,7 @@ void DRMProcessorClientImpl::inflate(std::string data, gourou::ByteArray& result if (ret != Z_OK) EXCEPTION(gourou::CLIENT_ZIP_ERROR, infstream.msg); - ret = ::inflate(&infstream, Z_SYNC_FLUSH); + ret = ::inflate(&infstream, Z_FINISH); while (ret == Z_OK || ret == Z_STREAM_END) { result.append(buffer, dataSize-infstream.avail_out); @@ -452,10 +452,11 @@ void DRMProcessorClientImpl::inflate(std::string data, gourou::ByteArray& result break; infstream.avail_out = (uInt)dataSize; // size of output infstream.next_out = (Bytef *)buffer; // output char array - ret = ::inflate(&infstream, Z_SYNC_FLUSH); + ret = ::inflate(&infstream, Z_FINISH); } - inflateEnd(&infstream); + if (ret == Z_STREAM_END) + ret = deflateEnd(&infstream); delete[] buffer; @@ -464,7 +465,7 @@ void DRMProcessorClientImpl::inflate(std::string data, gourou::ByteArray& result } void DRMProcessorClientImpl::deflate(std::string data, gourou::ByteArray& result, - int wbits, int compressionLevel) + int wbits, int compressionLevel) { unsigned int dataSize = data.size(); unsigned char* buffer = new unsigned char[dataSize]; @@ -486,7 +487,7 @@ void DRMProcessorClientImpl::deflate(std::string data, gourou::ByteArray& result if (ret != Z_OK) EXCEPTION(gourou::CLIENT_ZIP_ERROR, defstream.msg); - ret = ::deflate(&defstream, Z_SYNC_FLUSH); + ret = ::deflate(&defstream, Z_FINISH); while (ret == Z_OK || ret == Z_STREAM_END) { result.append(buffer, dataSize-defstream.avail_out); @@ -494,10 +495,11 @@ void DRMProcessorClientImpl::deflate(std::string data, gourou::ByteArray& result break; defstream.avail_out = (uInt)dataSize; // size of output defstream.next_out = (Bytef *)buffer; // output char array - ret = ::deflate(&defstream, Z_SYNC_FLUSH); + ret = ::deflate(&defstream, Z_FINISH); } - - deflateEnd(&defstream); + + if (ret == Z_STREAM_END) + ret = deflateEnd(&defstream); delete[] buffer;