kdecore: use the QString streaming operator in KSycocaEntry::read()

any change to the QString streaming operator would break reading of entries

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-10-31 01:18:46 +02:00
parent 92816d2320
commit 0d54213264
2 changed files with 26 additions and 45 deletions

View file

@ -22,10 +22,10 @@
#include <ksycoca.h> #include <ksycoca.h>
KSycocaEntryPrivate::KSycocaEntryPrivate(QDataStream &_str, int iOffset) KSycocaEntryPrivate::KSycocaEntryPrivate(QDataStream &s, int iOffset)
: offset(iOffset), deleted(false) : offset(iOffset), deleted(false)
{ {
KSycocaEntry::read( _str, path ); KSycocaEntry::read(s, path);
} }
KSycocaEntry::KSycocaEntry() KSycocaEntry::KSycocaEntry()
@ -43,52 +43,33 @@ KSycocaEntry::~KSycocaEntry()
delete d_ptr; delete d_ptr;
} }
void KSycocaEntry::read( QDataStream &s, QString &str ) void KSycocaEntry::read(QDataStream &s, QString &str)
{ {
quint32 bytes; s >> str;
s >> bytes; // read size of string if (s.status() != QDataStream::Ok) {
if ( bytes > 8192 ) { // null string or too big KSycoca::flagError();
if (bytes != 0xffffffff) str.clear();
KSycoca::flagError(); }
str.clear();
}
else if ( bytes > 0 ) { // not empty
int bt = bytes/2;
str.resize( bt );
QChar* ch = (QChar *) str.unicode();
char t[8192];
char *b = t;
s.readRawData( b, bytes );
while ( bt-- ) {
*ch++ = (ushort) (((ushort)b[0])<<8) | (uchar)b[1];
b += 2;
}
} else {
str.clear();
}
} }
void KSycocaEntry::read( QDataStream &s, QStringList &list ) void KSycocaEntry::read(QDataStream &s, QStringList &list)
{ {
list.clear(); list.clear();
quint32 count; quint32 count;
s >> count; // read size of list s >> count; // read size of list
if (count >= 1024) if (count >= 1024) {
{
KSycoca::flagError();
return;
}
for(quint32 i = 0; i < count; i++)
{
QString str;
read(s, str);
list.append( str );
if (s.atEnd())
{
KSycoca::flagError(); KSycoca::flagError();
return; return;
} }
} for(quint32 i = 0; i < count; i++) {
QString str;
read(s, str);
list.append(str);
if (s.atEnd()) {
KSycoca::flagError();
return;
}
}
} }
bool KSycocaEntry::isType(KSycocaType t) const bool KSycocaEntry::isType(KSycocaType t) const

View file

@ -69,8 +69,8 @@ public:
/** /**
* Safe demarshalling functions. * Safe demarshalling functions.
*/ */
static void read( QDataStream &s, QString &str ); static void read(QDataStream &s, QString &str);
static void read( QDataStream &s, QStringList &list ); static void read(QDataStream &s, QStringList &list);
/** /**
@ -122,7 +122,7 @@ public:
/** /**
* Sets whether or not this service is deleted * Sets whether or not this service is deleted
*/ */
void setDeleted( bool deleted ); void setDeleted(bool deleted);
/* /*