Zim: One more check for Zim header

This commit is contained in:
Abs62 2023-01-17 20:59:13 +03:00
parent 9a5e1e8910
commit 46a34e805c

10
zim.cc
View file

@ -63,6 +63,7 @@ using BtreeIndexing::IndexInfo;
DEF_EX_STR( exNotZimFile, "Not an Zim file", Dictionary::Ex )
DEF_EX_STR( exCantReadFile, "Can't read file", Dictionary::Ex )
DEF_EX_STR( exInvalidZimHeader, "Invalid Zim header", Dictionary::Ex )
DEF_EX( exUserAbort, "User abort", Dictionary::Ex )
@ -288,6 +289,9 @@ bool ZimFile::open()
if( read( reinterpret_cast< char * >( &zimHeader ), sizeof( zimHeader ) ) != sizeof( zimHeader ) )
return false;
if( zimHeader.magicNumber != 0x44D495A || zimHeader.mimeListPos != sizeof( zimHeader ) )
return false;
// Clusters in zim file may be placed in random order.
// We create sorted offsets list to calculate clusters size.
@ -1694,11 +1698,15 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
df.open();
ZIM_header const & zh = df.header();
bool new_namespaces = ( zh.majorVersion >= 6 && zh.minorVersion >= 1 );
if( zh.magicNumber != 0x44D495A )
throw exNotZimFile( i->c_str() );
if( zh.mimeListPos != sizeof( ZIM_header ) )
throw exInvalidZimHeader( i->c_str() );
bool new_namespaces = ( zh.majorVersion >= 6 && zh.minorVersion >= 1 );
{
int n = firstName.lastIndexOf( '/' );
initializing.indexingDictionary( firstName.mid( n + 1 ).toUtf8().constData() );