From a623a3d796fcf50a6475878479c55824c5a02113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Tue, 22 Feb 2022 20:58:30 +0100 Subject: [PATCH] Skip files with inflate errors during ePub decryption --- src/libgourou.cpp | 17 ++++++++++++++--- utils/drmprocessorclientimpl.cpp | 6 +++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/libgourou.cpp b/src/libgourou.cpp index aa8ce32..4fe1075 100644 --- a/src/libgourou.cpp +++ b/src/libgourou.cpp @@ -1010,9 +1010,20 @@ namespace gourou _clearData[dataOutLength] = 'Z'; clearData.resize(dataOutLength+1); - client->inflate(clearData, inflateData); - - client->zipWriteFile(zipHandler, encryptedFile, inflateData); + try + { + client->inflate(clearData, inflateData); + client->zipWriteFile(zipHandler, encryptedFile, inflateData); + } + catch(gourou::Exception& e) + { + if (e.getErrorCode() == CLIENT_ZIP_ERROR) + { + GOUROU_LOG(ERROR, e.what() << std::endl << "Skip file " << encryptedFile); + } + else + throw e; + } it->node().parent().remove_child(it->node()); } diff --git a/utils/drmprocessorclientimpl.cpp b/utils/drmprocessorclientimpl.cpp index c412484..b0244be 100644 --- a/utils/drmprocessorclientimpl.cpp +++ b/utils/drmprocessorclientimpl.cpp @@ -510,7 +510,12 @@ void DRMProcessorClientImpl::inflate(gourou::ByteArray& data, gourou::ByteArray& ret = ::inflate(&infstream, Z_FINISH); while (ret == Z_OK || ret == Z_STREAM_END || ret == Z_BUF_ERROR) { + // Real error + if (ret == Z_BUF_ERROR && infstream.avail_out == (uInt)dataSize) + EXCEPTION(gourou::CLIENT_ZIP_ERROR, "Inflate error, code " << zError(ret) << ", msg " << infstream.msg); + result.append(buffer, dataSize-infstream.avail_out); + if ((ret == Z_OK && infstream.avail_out != 0) || ret == Z_STREAM_END) break; infstream.avail_out = (uInt)dataSize; // size of output @@ -518,7 +523,6 @@ void DRMProcessorClientImpl::inflate(gourou::ByteArray& data, gourou::ByteArray& ret = ::inflate(&infstream, Z_FINISH); } - if (ret == Z_STREAM_END) ret = inflateEnd(&infstream);