Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit b426fa68 authored by Volker Krause's avatar Volker Krause

Search for the next valid RCT2 field

If the size field is actually wrong (e.g. due to wrongly using Unicode
rather than UTF-8 byte stream length), this gives us a chance to recover.
parent a7ea0791
......@@ -248,7 +248,7 @@ Rct2TicketField::Rct2TicketField(const char *data, int size)
, m_size(size)
{
if (size <= 13) { // too small
qCWarning(Log) << "Found too small RCT2 field";
qCWarning(Log) << "Found too small RCT2 field:" << size;
m_data = nullptr;
return;
}
......@@ -262,7 +262,7 @@ Rct2TicketField::Rct2TicketField(const char *data, int size)
// size is too large
if (this->size() > m_size) {
qCWarning(Log) << "Found RCT2 field with invalid size";
qCWarning(Log) << "Found RCT2 field with invalid size" << this->size() << m_size;
m_data = nullptr;
return;
}
......@@ -305,9 +305,22 @@ QString Rct2TicketField::text() const
Rct2TicketField Rct2TicketField::next() const
{
if (m_size > size()) {
return Rct2TicketField(m_data + size(), m_size - size());
const auto thisSize = size();
const auto remaining = m_size - size();
if (remaining < 0) {
return {};
}
// search for the next field
// in theory this should always trigger at i == 0, unless
// the size field is wrong, which happens unfortunately
for (int i = 0; i < remaining - 13; ++i) {
Rct2TicketField f(m_data + thisSize + i, remaining - i);
if (!f.isNull()) {
return f;
}
}
return {};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment