|
@@ -43,15 +43,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
#include <assimp/ai_assert.h>
|
|
#include <assimp/ai_assert.h>
|
|
|
#include <assimp/Exceptional.h>
|
|
#include <assimp/Exceptional.h>
|
|
|
|
|
|
|
|
-
|
|
|
|
|
namespace Assimp {
|
|
namespace Assimp {
|
|
|
|
|
|
|
|
struct Compression::impl {
|
|
struct Compression::impl {
|
|
|
bool mOpen;
|
|
bool mOpen;
|
|
|
z_stream mZSstream;
|
|
z_stream mZSstream;
|
|
|
FlushMode mFlushMode;
|
|
FlushMode mFlushMode;
|
|
|
|
|
+
|
|
|
impl() :
|
|
impl() :
|
|
|
mOpen(false),
|
|
mOpen(false),
|
|
|
|
|
+ mZSstream(),
|
|
|
mFlushMode(Compression::FlushMode::NoFlush) {
|
|
mFlushMode(Compression::FlushMode::NoFlush) {
|
|
|
// empty
|
|
// empty
|
|
|
}
|
|
}
|
|
@@ -97,8 +98,6 @@ bool Compression::open(Format format, FlushMode flush, int windowBits) {
|
|
|
return mImpl->mOpen;
|
|
return mImpl->mOpen;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-constexpr size_t MYBLOCK = 32786;
|
|
|
|
|
-
|
|
|
|
|
static int getFlushMode(Compression::FlushMode flush) {
|
|
static int getFlushMode(Compression::FlushMode flush) {
|
|
|
int z_flush = 0;
|
|
int z_flush = 0;
|
|
|
switch (flush) {
|
|
switch (flush) {
|
|
@@ -119,15 +118,19 @@ static int getFlushMode(Compression::FlushMode flush) {
|
|
|
return z_flush;
|
|
return z_flush;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+constexpr size_t MYBLOCK = 32786;
|
|
|
|
|
+
|
|
|
size_t Compression::decompress(const void *data, size_t in, std::vector<char> &uncompressed) {
|
|
size_t Compression::decompress(const void *data, size_t in, std::vector<char> &uncompressed) {
|
|
|
ai_assert(mImpl != nullptr);
|
|
ai_assert(mImpl != nullptr);
|
|
|
|
|
+ if (data == nullptr || in == 0) {
|
|
|
|
|
+ return 0l;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
mImpl->mZSstream.next_in = (Bytef*)(data);
|
|
mImpl->mZSstream.next_in = (Bytef*)(data);
|
|
|
mImpl->mZSstream.avail_in = (uInt)in;
|
|
mImpl->mZSstream.avail_in = (uInt)in;
|
|
|
|
|
|
|
|
int ret = 0;
|
|
int ret = 0;
|
|
|
size_t total = 0l;
|
|
size_t total = 0l;
|
|
|
-
|
|
|
|
|
const int flushMode = getFlushMode(mImpl->mFlushMode);
|
|
const int flushMode = getFlushMode(mImpl->mFlushMode);
|
|
|
if (flushMode == Z_FINISH) {
|
|
if (flushMode == Z_FINISH) {
|
|
|
mImpl->mZSstream.avail_out = static_cast<uInt>(uncompressed.size());
|
|
mImpl->mZSstream.avail_out = static_cast<uInt>(uncompressed.size());
|
|
@@ -160,6 +163,10 @@ size_t Compression::decompress(const void *data, size_t in, std::vector<char> &u
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
size_t Compression::decompressBlock(const void *data, size_t in, char *out, size_t availableOut) {
|
|
size_t Compression::decompressBlock(const void *data, size_t in, char *out, size_t availableOut) {
|
|
|
|
|
+ ai_assert(mImpl != nullptr);
|
|
|
|
|
+ if (data == nullptr || in == 0 || out == nullptr || availableOut == 0) {
|
|
|
|
|
+ return 0l;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// push data to the stream
|
|
// push data to the stream
|
|
|
mImpl->mZSstream.next_in = (Bytef *)data;
|
|
mImpl->mZSstream.next_in = (Bytef *)data;
|
|
@@ -169,8 +176,9 @@ size_t Compression::decompressBlock(const void *data, size_t in, char *out, size
|
|
|
|
|
|
|
|
// and decompress the data ....
|
|
// and decompress the data ....
|
|
|
int ret = ::inflate(&mImpl->mZSstream, Z_SYNC_FLUSH);
|
|
int ret = ::inflate(&mImpl->mZSstream, Z_SYNC_FLUSH);
|
|
|
- if (ret != Z_OK && ret != Z_STREAM_END)
|
|
|
|
|
|
|
+ if (ret != Z_OK && ret != Z_STREAM_END) {
|
|
|
throw DeadlyImportError("X: Failed to decompress MSZIP-compressed data");
|
|
throw DeadlyImportError("X: Failed to decompress MSZIP-compressed data");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
::inflateReset(&mImpl->mZSstream);
|
|
::inflateReset(&mImpl->mZSstream);
|
|
|
::inflateSetDictionary(&mImpl->mZSstream, (const Bytef *)out, (uInt)availableOut - mImpl->mZSstream.avail_out);
|
|
::inflateSetDictionary(&mImpl->mZSstream, (const Bytef *)out, (uInt)availableOut - mImpl->mZSstream.avail_out);
|