1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
Description: improve the Capella import
Since the reporter of CVE-2023-44428 does not offer any
information (testcases, reproducers or patches), attempt
to improve the situation by plugging missing initialisation
and other checks. Besides that, do not load untrusted files.
.
Endianness is also corrected.
Author: mirabilos <tg@debian.org>
Forwarded: no
--- a/mscore/capella.cpp
+++ b/mscore/capella.cpp
@@ -23,6 +23,7 @@
//
#include <assert.h>
#include "libmscore/mscore.h"
+#include <QtEndian>
#include "capella.h"
#include "libmscore/score.h"
#include "libmscore/part.h"
@@ -68,6 +69,7 @@ const char* Capella::errmsg[] = {
"bad voice signature",
"bad staff signature",
"bad system signature",
+ "short read",
};
//---------------------------------------------------------
@@ -1918,15 +1920,14 @@ void ChordObj::read()
// return false on error
//---------------------------------------------------------
-bool Capella::read(void* p, qint64 len)
+void Capella::read(void* p, qint64 len)
{
if (len == 0)
- return true;
+ return;
qint64 rv = f->read((char*)p, len);
if (rv != len)
- return false;
+ throw Capella::Error::SHORT_READ;
curPos += len;
- return true;
}
//---------------------------------------------------------
@@ -1957,9 +1958,9 @@ char Capella::readChar()
short Capella::readWord()
{
- short c;
- read(&c, 2);
- return c;
+ uchar buf[sizeof(qint16)];
+ read(buf, sizeof(buf));
+ return qFromLittleEndian<qint16>(buf);
}
//---------------------------------------------------------
@@ -1968,9 +1969,9 @@ short Capella::readWord()
int Capella::readDWord()
{
- int c;
- read(&c, 4);
- return c;
+ uchar buf[sizeof(qint32)];
+ read(buf, sizeof(buf));
+ return qFromLittleEndian<qint32>(buf);
}
//---------------------------------------------------------
@@ -1979,9 +1980,9 @@ int Capella::readDWord()
int Capella::readLong()
{
- int c;
- read(&c, 4);
- return c;
+ uchar buf[sizeof(qint32)];
+ read(buf, sizeof(buf));
+ return qFromLittleEndian<qint32>(buf);
}
//---------------------------------------------------------
@@ -1993,14 +1994,14 @@ unsigned Capella::readUnsigned()
unsigned char c;
read(&c, 1);
if (c == 254) {
- unsigned short s;
- read(&s, 2);
- return s;
+ uchar buf[sizeof(quint16)];
+ read(buf, sizeof(buf));
+ return qFromLittleEndian<quint16>(buf);
}
else if (c == 255) {
- unsigned s;
- read(&s, 4);
- return s;
+ uchar buf[sizeof(quint32)];
+ read(buf, sizeof(buf));
+ return qFromLittleEndian<quint32>(buf);
}
else
return c;
@@ -2015,14 +2016,14 @@ int Capella::readInt()
signed char c;
read(&c, 1);
if (c == -128) {
- short s;
- read(&s, 2);
- return s;
+ uchar buf[sizeof(qint16)];
+ read(buf, sizeof(buf));
+ return qFromLittleEndian<qint16>(buf);
}
else if (c == 127) {
- int s;
- read(&s, 4);
- return s;
+ uchar buf[sizeof(qint32)];
+ read(buf, sizeof(buf));
+ return qFromLittleEndian<qint32>(buf);
}
else
return c;
@@ -2156,8 +2157,7 @@ void Capella::readStaveLayout(CapStaffLa
default:
{
char lines[11];
- f->read(lines, 11);
- curPos += 11;
+ read(lines, 11);
}
break;
}
@@ -2190,16 +2190,14 @@ void Capella::readStaveLayout(CapStaffLa
Q_UNUSED(iMin);
uchar n = readByte();
Q_ASSERT (n > 0 and iMin + n <= 128);
- f->read(sl->soundMapIn, n);
- curPos += n;
+ read(sl->soundMapIn, n);
}
if (sl->bSoundMapOut) { // Umleitungstabelle für das Vorspielen
unsigned char iMin = readByte();
Q_UNUSED(iMin);
unsigned char n = readByte();
Q_ASSERT (n > 0 and iMin + n <= 128);
- f->read(sl->soundMapOut, n);
- curPos += n;
+ read(sl->soundMapOut, n);
}
sl->sound = readInt();
sl->volume = readInt();
--- a/mscore/capella.h
+++ b/mscore/capella.h
@@ -313,11 +313,13 @@ class MetafileObj : public BasicRectObj
class LineObj : public BasicDrawObj {
public:
- LineObj(Capella* c) : BasicDrawObj(CapellaType::LINE, c) {}
- LineObj(CapellaType t, Capella* c) : BasicDrawObj(t, c) {}
+ LineObj(Capella* c) : BasicDrawObj(CapellaType::LINE, c),
+ color(Qt::black), lineWidth(1) {}
+ LineObj(CapellaType t, Capella* c) : BasicDrawObj(t, c),
+ color(Qt::black), lineWidth(1) {}
void read();
- QPointF pt1, pt2;
+ QPointF pt1, pt2; // note default constructor inits to (0, 0)
QColor color;
char lineWidth;
};
@@ -385,6 +387,7 @@ class VoltaObj : public BasicDrawObj {
public:
VoltaObj(Capella* c)
: BasicDrawObj(CapellaType::VOLTA, c), x0(0), x1(0), y(0),
+ color(Qt::black),
bLeft(false), bRight(false), bDotted(false),
allNumbers(false), from(0), to(0) {}
void read();
@@ -423,7 +426,7 @@ class GuitarObj : public BasicDrawObj {
class TrillObj : public BasicDrawObj {
public:
TrillObj(Capella* c) : BasicDrawObj(CapellaType::TRILL, c), x0(0),
- x1(0), y(0), trillSign(true) {}
+ x1(0), y(0), color(Qt::black), trillSign(true) {}
void read();
void readCapx(XmlReader& e);
@@ -682,7 +685,7 @@ class Capella {
public:
enum class Error : char { CAP_NO_ERROR, BAD_SIG, CAP_EOF, BAD_VOICE_SIG,
- BAD_STAFF_SIG, BAD_SYSTEM_SIG
+ BAD_STAFF_SIG, BAD_SYSTEM_SIG, SHORT_READ
};
Capella();
@@ -702,7 +705,8 @@ class Capella {
QString readQString();
void readExtra();
QList<BasicDrawObj*> readDrawObjectArray();
- bool read(void* p, qint64 len);
+ // was bool, but nothing checked the return value, so it throws now
+ void read(void* p, qint64 len);
QFont readFont();
QPointF readPoint();
--- a/mscore/capxml.cpp
+++ b/mscore/capxml.cpp
@@ -304,7 +304,7 @@ void ChordObj::readCapx(XmlReader& e)
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
if (tag == "duration") {
- unsigned int dummy;
+ unsigned int dummy = 0;
BasicDurationalObj::readCapx(e, dummy);
}
else if (tag == "display") {
|