Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#24704 ensure xml parse can cope with comments after empty notes #24709

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

wizofaus
Copy link
Contributor

Resolves: #24704

  • I signed the CLA
  • The title of the PR describes the problem it addresses
  • Each commit's message describes its purpose and effects, and references the issue it resolves
  • If changes are extensive, there is a sequence of easily reviewable commits
  • The code in the PR follows the coding rules
  • There are no unnecessary changes
  • The code compiles and runs on my machine, preferably after each commit individually
  • I created a unit test or vtest to verify the changes I made (if applicable)

@@ -157,7 +157,7 @@ static std::pair<XMLNode*, XmlStreamReader::TokenType> resolveNode(XMLNode* curr
}

XMLNode* sibling = currentNode->NextSibling();
if (!sibling || sibling->ToElement() || sibling->ToText()) {
if (!sibling || sibling->ToElement() || sibling->ToText() || sibling->ToComment()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the actual fix

return m_xml->doc.ErrorLineNum();
int64_t lineNum = m_xml->doc.ErrorLineNum();
if (lineNum == 0 && m_xml->node) {
lineNum = m_xml->node->GetLineNum();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to return a more helpful line number based on the most recently processed node

@@ -1088,6 +1088,9 @@ Err MusicXMLParserPass1::parse()

if (!found) {
m_logger->logError(u"this is not a MusicXML score-partwise file, node <score-partwise> not found", &m_e);
if (!m_e.errorString().isEmpty()) {
m_errors += errorStringWithLocation(m_e.lineNumber(), m_e.columnNumber(), m_e.errorString()) + '\n';
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure at least some useful error info shown if score-partwise can't be detected due to an unrecoverable low-level parsing error

@@ -2923,7 +2923,7 @@ void MusicXMLParserPass2::staffDetails(const String& partId, Measure* measure)

staff_idx_t staffIdx = m_score->staffIdx(part) + n;

StringData* t = new StringData;
StringData stringData;
Copy link
Contributor Author

@wizofaus wizofaus Sep 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memory leak
Admittedly the term "stringData" isn't ideal, as it's not referring to "string" as in a C++ type, rather a guitar string!

}
} else if (stringData.strings() > 0) {
m_logger->logError(u"trying to change string data for non-TAB staff (not supported)", &m_e);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incorrect logic, this was being logged as an error for any staff that wasn't a TAB staff (didn't affect what was shown to user though)

@oktophonie oktophonie requested a review from miiizen September 14, 2024 06:38
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Sep 14, 2024
Backport of musescore#24709, the only relevant part for Mu3, a memory leak and an incorrect logic for logging an error, both in importmxmlpass2.cpp
@miiizen
Copy link
Contributor

miiizen commented Sep 18, 2024

Thanks for this fix - the changes in xmlstreamreader and pass1 look good to me. I'd also like to get this in the next patch - would you be able to separate this into a separate commit from the changes in pass2?

I also think the error is totally unneeded in pass2 and can just be removed. staff-lines doesn't just refer to strings on TAB staves, so I'm not sure what purpose it serves.

@wizofaus
Copy link
Contributor Author

wizofaus commented Sep 18, 2024

Thanks for this fix - the changes in xmlstreamreader and pass1 look good to me. I'd also like to get this in the next patch - would you be able to separate this into a separate commit from the changes in pass2?

I also think the error is totally unneeded in pass2 and can just be removed. staff-lines doesn't just refer to strings on TAB staves, so I'm not sure what purpose it serves.

Happy to remove the error around stringData but is there a reason you don't want the pass2 changes in the same commit? There's no good reason for that StringData to be allocated on the heap (then never freed).

@Jojo-Schmitz
Copy link
Contributor

It'd be too much for 4.4.3 I guess?

@wizofaus
Copy link
Contributor Author

wizofaus commented Sep 18, 2024

I'm not even fussed if it goes in 4.4.3, I just wrote my own tool to clean up Musicxml files first (I had to anyway as the timing was incorrect for notes in staff 2).
The bug's been present since May 2022, FWIW. It's not hard to work around (just a search & replace to strip comments from your xml files first).

@miiizen miiizen mentioned this pull request Sep 19, 2024
@Jojo-Schmitz
Copy link
Contributor

Rebase needed. Seems this at least partly got merged into 4.4.3.

Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Dec 28, 2024
Backport of musescore#24709, the only relevant part for Mu3, a memory leak and an incorrect logic for logging an error, both in importmxmlpass2.cpp
@Jojo-Schmitz
Copy link
Contributor

Still needs a rebase

Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Jan 14, 2025
Backport of musescore#24709, the only relevant part for Mu3, a memory leak and an incorrect logic for logging an error, both in importmxmlpass2.cpp
@cbjeukendrup
Copy link
Contributor

Rebased

@miiizen miiizen merged commit 5b744a0 into musescore:master Feb 27, 2025
11 checks passed
Jojo-Schmitz pushed a commit to Jojo-Schmitz/MuseScore that referenced this pull request Feb 27, 2025
Backport of musescore#24709, the only relevant part for Mu3, a memory leak and an incorrect logic for logging an error, both in importmxmlpass2.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MusicXml parser is broken when comment follows empty node
4 participants