Skip to content

Commit

Permalink
fix #92306 - crash when importing MusicXML with invalid time sig
Browse files Browse the repository at this point in the history
  • Loading branch information
lvinken committed Jan 16, 2016
1 parent ac4819d commit af1ec14
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 2 deletions.
10 changes: 9 additions & 1 deletion mscore/importmxmlpass1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2163,7 +2163,7 @@ static bool determineTimeSig(const QString beats, const QString beatType, const
}
else {
if (!timeSymbol.isEmpty() && timeSymbol != "normal") {
qDebug("ImportMusicXml: time symbol <%s> not recognized with beats=%s and beat-type=%s",
qDebug("determineTimeSig: time symbol <%s> not recognized with beats=%s and beat-type=%s",
qPrintable(timeSymbol), qPrintable(beats), qPrintable(beatType)); // TODO
return false;
}
Expand All @@ -2173,6 +2173,14 @@ static bool determineTimeSig(const QString beats, const QString beatType, const
for (int i = 0; i < list.size(); i++)
bts += list.at(i).toInt();
}

// determine if bts and btp are valid
if (bts <= 0 || btp <=0) {
qDebug("determineTimeSig: beats=%s and/or beat-type=%s not recognized",
qPrintable(beats), qPrintable(beatType)); // TODO
return false;
}

return true;
}

Expand Down
10 changes: 9 additions & 1 deletion mscore/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3577,7 +3577,7 @@ static bool determineTimeSig(const QString beats, const QString beatType, const
}
else {
if (!timeSymbol.isEmpty() && timeSymbol != "normal") {
qDebug("ImportMusicXml: time symbol <%s> not recognized with beats=%s and beat-type=%s",
qDebug("determineTimeSig: time symbol <%s> not recognized with beats=%s and beat-type=%s",
qPrintable(timeSymbol), qPrintable(beats), qPrintable(beatType)); // TODO
return false;
}
Expand All @@ -3587,6 +3587,14 @@ static bool determineTimeSig(const QString beats, const QString beatType, const
for (int i = 0; i < list.size(); i++)
bts += list.at(i).toInt();
}

// determine if bts and btp are valid
if (bts <= 0 || btp <=0) {
qDebug("determineTimeSig: beats=%s and/or beat-type=%s not recognized",
qPrintable(beats), qPrintable(beatType)); // TODO
return false;
}

return true;
}

Expand Down
Binary file added mtest/musicxml/io/testInvalidTimesig.pdf
Binary file not shown.
88 changes: 88 additions & 0 deletions mtest/musicxml/io/testInvalidTimesig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise>
<work>
<work-number>MuseScore testfile</work-number>
<work-title>Invalid time signature (ignored)</work-title>
</work>
<identification>
<encoding>
<software>MuseScore 0.7.0</software>
<encoding-date>2007-09-10</encoding-date>
<supports element="accidental" type="yes"/>
<supports element="beam" type="yes"/>
<supports element="print" attribute="new-page" type="no"/>
<supports element="print" attribute="new-system" type="no"/>
<supports element="stem" type="yes"/>
</encoding>
<miscellaneous>
<miscellaneous-field name="description">
Verify an invalid time signature does not crash MuseScore.
Note that it will simply be ignored.
</miscellaneous-field>
</miscellaneous>
</identification>
<part-list>
<score-part id="P1">
<part-name>Music</part-name>
<score-instrument id="P1-I1">
<instrument-name>Music</instrument-name>
</score-instrument>
<midi-device id="P1-I1" port="1"></midi-device>
<midi-instrument id="P1-I1">
<midi-channel>1</midi-channel>
<midi-program>1</midi-program>
<volume>78.7402</volume>
<pan>0</pan>
</midi-instrument>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<fifths>0</fifths>
</key>
<time>
<beats>a</beats>
<beat-type>b</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<note>
<pitch>
<step>C</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
<note>
<pitch>
<step>D</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
<note>
<pitch>
<step>E</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
</measure>
</part>
</score-partwise>
78 changes: 78 additions & 0 deletions mtest/musicxml/io/testInvalidTimesig_ref.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise>
<work>
<work-number>MuseScore testfile</work-number>
<work-title>Invalid time signature (ignored)</work-title>
</work>
<identification>
<encoding>
<software>MuseScore 0.7.0</software>
<encoding-date>2007-09-10</encoding-date>
<supports element="accidental" type="yes"/>
<supports element="beam" type="yes"/>
<supports element="print" attribute="new-page" type="no"/>
<supports element="print" attribute="new-system" type="no"/>
<supports element="stem" type="yes"/>
</encoding>
</identification>
<part-list>
<score-part id="P1">
<part-name>Music</part-name>
<score-instrument id="P1-I1">
<instrument-name>Music</instrument-name>
</score-instrument>
<midi-device id="P1-I1" port="1"></midi-device>
<midi-instrument id="P1-I1">
<midi-channel>1</midi-channel>
<midi-program>1</midi-program>
<volume>78.7402</volume>
<pan>0</pan>
</midi-instrument>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<fifths>0</fifths>
</key>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<note>
<pitch>
<step>C</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
<note>
<pitch>
<step>D</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
<note>
<pitch>
<step>E</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
</measure>
</part>
</score-partwise>
1 change: 1 addition & 0 deletions mtest/musicxml/io/tst_mxml_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private slots:
void implicitMeasure1() { mxmlIoTest("testImplicitMeasure1"); }
void incorrectStaffNumber() { mxmlIoTestRef("testIncorrectStaffNumber"); }
void instrumentChangeMIDIportExport() { mxmlMscxExportTestRef("testInstrumentChangeMIDIportExport"); }
void invalidTimesig() { mxmlIoTestRef("testInvalidTimesig"); }
void invisibleElements() { mxmlIoTest("testInvisibleElements"); }
void keysig1() { mxmlIoTest("testKeysig1"); }
void keysig2() { mxmlIoTest("testKeysig2"); }
Expand Down

0 comments on commit af1ec14

Please sign in to comment.