Fix broken importer and add some review findings2

pull/4381/head
Kim Kulling 2022-02-13 18:44:22 +01:00
parent 3e09d462fa
commit 52b6c4f7c0
6 changed files with 21 additions and 16 deletions

View File

@ -175,7 +175,7 @@ void BlenderImporter::InternReadFile(const std::string &pFile,
size_t total = 0;
Compression compression;
if (compression.open(Compression::Format::Binary, Compression::FlushMode::Finish) ) {
if (compression.open(Compression::Format::Binary, Compression::FlushMode::NoFlush, 16 + MAX_WBITS)) {
total = compression.decompress((unsigned char *)reader->GetPtr(), reader->GetRemainingSize(), uncompressed);
compression.close();
}

View File

@ -567,7 +567,7 @@ void ReadBinaryDataArray(char type, uint32_t count, const char*& data, const cha
// zlib/deflate, next comes ZIP head (0x78 0x01)
// see http://www.ietf.org/rfc/rfc1950.txt
Compression compress;
if (compress.open(Compression::Format::Binary, Compression::FlushMode::Finish)) {
if (compress.open(Compression::Format::Binary, Compression::FlushMode::Finish,0)) {
compress.decompress(data, comp_len, buff);
compress.close();
}

View File

@ -188,7 +188,7 @@ XFileParser::XFileParser(const std::vector<char> &pBuffer) :
Compression compression;
uncompressed.resize(est_out + 1);
char *out = &uncompressed.front();
if (compression.open(mIsBinaryFormat ? Compression::Format::Binary : Compression::Format::ASCII, Compression::FlushMode::SyncFlush)) {
if (compression.open(mIsBinaryFormat ? Compression::Format::Binary : Compression::Format::ASCII, Compression::FlushMode::SyncFlush, -MAX_WBITS)) {
while (mP + 3 < mEnd) {
uint16_t ofs = *((uint16_t *)mP);
AI_SWAP2(ofs);

View File

@ -132,7 +132,7 @@ void XGLImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
Compression compression;
size_t total = 0l;
if (compression.open(Compression::Format::Binary, Compression::FlushMode::NoFlush)) {
if (compression.open(Compression::Format::Binary, Compression::FlushMode::NoFlush, -MAX_WBITS)) {
// skip two extra bytes, zgl files do carry a crc16 upfront (I think)
raw_reader->IncPtr(2);
total = compression.decompress((unsigned char *)raw_reader->GetPtr(), raw_reader->GetRemainingSize(), uncompressed);

View File

@ -43,11 +43,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/ai_assert.h>
#include <assimp/Exceptional.h>
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
#include <zlib.h>
#else
#include "../contrib/zlib/zlib.h"
#endif
namespace Assimp {
@ -73,7 +68,7 @@ Compression::~Compression() {
delete mImpl;
}
bool Compression::open(Format format, FlushMode flush) {
bool Compression::open(Format format, FlushMode flush, int windowBits) {
ai_assert(mImpl != nullptr);
if (mImpl->mOpen) {
@ -92,7 +87,11 @@ bool Compression::open(Format format, FlushMode flush) {
}
// raw decompression without a zlib or gzip header
inflateInit(&mImpl->mZSstream);
if (windowBits == 0) {
inflateInit(&mImpl->mZSstream);
} else {
inflateInit2(&mImpl->mZSstream, windowBits);
}
mImpl->mOpen = true;
return mImpl->mOpen;

View File

@ -41,6 +41,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
#include <zlib.h>
#else
#include "../contrib/zlib/zlib.h"
#endif
#include <vector>
namespace Assimp {
@ -49,20 +55,20 @@ namespace Assimp {
class Compression {
public:
enum class Format {
InvalidFormat = -1,
Binary = 0,
ASCII,
NumFormats,
InvalidFormat
NumFormats
};
enum class FlushMode {
InvalidFormat = -1,
NoFlush = 0,
SyncFlush,
Finish,
NumModes,
InvalidMode
NumModes
};
/// @brief The class constructor.
@ -73,7 +79,7 @@ public:
/// @brief Will open the access to the compression.
/// @return true if close was successful, false if not.
bool open(Format format, FlushMode flush);
bool open(Format format, FlushMode flush, int windowBits);
/// @brief Will return the open state.
/// @return true if the access is opened, false if not.