mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
Merge pull request #1584 from xiaoyifang/fix/slob-truncate
fix: slob truncated file check.
This commit is contained in:
commit
4ac44e9a48
|
@ -58,6 +58,7 @@ using BtreeIndexing::IndexedWords;
|
||||||
using BtreeIndexing::IndexInfo;
|
using BtreeIndexing::IndexInfo;
|
||||||
|
|
||||||
DEF_EX_STR( exNotSlobFile, "Not an Slob file", Dictionary::Ex )
|
DEF_EX_STR( exNotSlobFile, "Not an Slob file", Dictionary::Ex )
|
||||||
|
DEF_EX( exTruncateFile, "Slob file truncated", Dictionary::Ex )
|
||||||
using Dictionary::exCantReadFile;
|
using Dictionary::exCantReadFile;
|
||||||
DEF_EX_STR( exCantDecodeFile, "Can't decode file", Dictionary::Ex )
|
DEF_EX_STR( exCantDecodeFile, "Can't decode file", Dictionary::Ex )
|
||||||
DEF_EX_STR( exNoCodecFound, "No text codec found", Dictionary::Ex )
|
DEF_EX_STR( exNoCodecFound, "No text codec found", Dictionary::Ex )
|
||||||
|
@ -323,8 +324,8 @@ void SlobFile::open( const QString & name )
|
||||||
encoding = readTinyText();
|
encoding = readTinyText();
|
||||||
|
|
||||||
codec = QTextCodec::codecForName( encoding.toLatin1() );
|
codec = QTextCodec::codecForName( encoding.toLatin1() );
|
||||||
if ( codec == 0 ) {
|
if ( codec == nullptr ) {
|
||||||
error = QString( "for encoding \"" ) + encoding + "\"";
|
error = QString( R"(for encoding "%1")" ).arg( encoding );
|
||||||
throw exNoCodecFound( string( error.toUtf8().data() ) );
|
throw exNoCodecFound( string( error.toUtf8().data() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,6 +384,11 @@ void SlobFile::open( const QString & name )
|
||||||
break;
|
break;
|
||||||
fileSize = qFromBigEndian( tmp );
|
fileSize = qFromBigEndian( tmp );
|
||||||
|
|
||||||
|
//truncated file
|
||||||
|
if ( file.size() < fileSize ) {
|
||||||
|
throw exTruncateFile();
|
||||||
|
}
|
||||||
|
|
||||||
if ( file.read( (char *)&cnt, sizeof( cnt ) ) != sizeof( cnt ) )
|
if ( file.read( (char *)&cnt, sizeof( cnt ) ) != sizeof( cnt ) )
|
||||||
break;
|
break;
|
||||||
refsCount = qFromBigEndian( cnt );
|
refsCount = qFromBigEndian( cnt );
|
||||||
|
@ -672,13 +678,7 @@ SlobDictionary::SlobDictionary( string const & id, string const & indexFile, vec
|
||||||
idxHeader( idx.read< IdxHeader >() )
|
idxHeader( idx.read< IdxHeader >() )
|
||||||
{
|
{
|
||||||
// Open data file
|
// Open data file
|
||||||
|
|
||||||
try {
|
|
||||||
sf.open( dictionaryFiles[ 0 ].c_str() );
|
sf.open( dictionaryFiles[ 0 ].c_str() );
|
||||||
}
|
|
||||||
catch ( std::exception & e ) {
|
|
||||||
gdWarning( "Slob dictionary initializing failed: %s, error: %s\n", dictionaryFiles[ 0 ].c_str(), e.what() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize the indexes
|
// Initialize the indexes
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue