Skip to content

Commit 065f517

Browse files
committed
Remove custom compression levels
As they were causing memory corruption.
1 parent 2850724 commit 065f517

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

source/mod_installer.h

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,8 @@ bool paddable(u64 padSize) {
6868
return !(padSize == 1 || padSize == 2 || padSize == 5);
6969
}
7070

71-
void setZSTDCustomLvl(ZSTD_CCtx* cctx, int level) {
72-
if(level <= ZSTD_maxCLevel())
73-
ZSTD_CCtx_setParameter(compContext, ZSTD_c_compressionLevel, level);
74-
else if(level == ZSTD_maxCLevel() + 1) {
75-
ZSTD_CCtx_setParameter(compContext, ZSTD_c_compressionLevel, 22);
76-
ZSTD_CCtx_setParameter(compContext, ZSTD_c_strategy, ZSTD_btopt);
77-
}
78-
else if(level == ZSTD_maxCLevel() + 2) {
79-
ZSTD_CCtx_setParameter(compContext, ZSTD_c_compressionLevel, 22);
80-
ZSTD_CCtx_setParameter(compContext, ZSTD_c_minMatch, 4);
81-
ZSTD_CCtx_setParameter(compContext, ZSTD_c_strategy, ZSTD_greedy);
82-
}
83-
}
84-
8571
bool compressFile(const char* path, u64 compSize, u64 &dataSize, char* outBuff, u64 bufSize)
8672
{
87-
const int ZSTDCustom_maxCLevel = ZSTD_maxCLevel() + 2;
8873
FILE* inFile = fopen(path, "rb");
8974
fseek(inFile, 0, SEEK_END);
9075
u64 inSize = ftell(inFile);
@@ -104,7 +89,7 @@ bool compressFile(const char* path, u64 compSize, u64 &dataSize, char* outBuff,
10489
ZSTD_CCtx_setParameter(compContext, ZSTD_c_checksumFlag, 0);
10590
ZSTD_CCtx_setParameter(compContext, ZSTD_c_dictIDFlag, 1);
10691
do {
107-
setZSTDCustomLvl(compContext, compLvl++);
92+
ZSTD_CCtx_setParameter(compContext, ZSTD_c_compressionLevel, compLvl++);
10893
dataSize = ZSTD_compress2(compContext, outBuff, bufSize, inBuff, inSize);
10994
if(ZSTD_isError(dataSize) && dataSize != 0xffffffffffffffba)
11095
log("%s Error at lvl %d: %lx %s\n", path, compLvl, dataSize, ZSTD_getErrorName(dataSize));
@@ -115,9 +100,9 @@ bool compressFile(const char* path, u64 compSize, u64 &dataSize, char* outBuff,
115100
}
116101
if(compLvl==10) compLvl = 17; // skip arbitrary amount of levels for speed.
117102
}
118-
while((dataSize > compSize || ZSTD_isError(dataSize) || !paddable(compSize - dataSize)) && compLvl <= ZSTDCustom_maxCLevel);
103+
while((dataSize > compSize || ZSTD_isError(dataSize) || !paddable(compSize - dataSize)) && compLvl <= ZSTD_maxCLevel());
119104

120-
if(compLvl > ZSTDCustom_maxCLevel) {
105+
if(compLvl > ZSTD_maxCLevel()) {
121106
if(bytesAway != ULONG_MAX)
122107
log("%lu bytes too large ", bytesAway);
123108
return false;

0 commit comments

Comments
 (0)