Handle frame image dictionary creation failures.

This commit is contained in:
Bartosz Taudul 2021-11-20 03:30:28 +01:00
parent b4dab753e6
commit 8d65b190d6
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -8077,13 +8077,23 @@ void Worker::Write( FileWrite& f, bool fiDict )
params.zParams.compressionLevel = 3; params.zParams.compressionLevel = 3;
auto dict = new char[DictSize]; auto dict = new char[DictSize];
const auto finalDictSize = (uint32_t)ZDICT_optimizeTrainFromBuffer_fastCover( dict, DictSize, sdata, ssize, sNum, &params ); const auto dictret = ZDICT_optimizeTrainFromBuffer_fastCover( dict, DictSize, sdata, ssize, sNum, &params );
auto zdict = ZSTD_createCDict( dict, finalDictSize, 3 ); if( dictret <= DictSize )
{
const auto finalDictSize = uint32_t( dictret );
auto zdict = ZSTD_createCDict( dict, finalDictSize, 3 );
f.Write( &finalDictSize, sizeof( finalDictSize ) ); f.Write( &finalDictSize, sizeof( finalDictSize ) );
f.Write( dict, finalDictSize ); f.Write( dict, finalDictSize );
ZSTD_freeCDict( zdict );
}
else
{
uint32_t zero = 0;
f.Write( &zero, sizeof( zero ) );
}
ZSTD_freeCDict( zdict );
delete[] dict; delete[] dict;
delete[] ssize; delete[] ssize;
delete[] sdata; delete[] sdata;