lenmus / lomse

A C++ library for rendering, editing and playing back music scores.
MIT License
120 stars 28 forks source link

Fix reading compressed MusicXML files encoded in UTF-16 #321

Closed dmitrio95 closed 3 years ago

dmitrio95 commented 3 years ago

This PR fixes an issue with reading some compressed MusicXML files. Two example files are MozaChloSample and MozaVeilSample from this example set (these files also seem to be available in the regression test repository). Uncompressed versions of these files are opened fine but compressed .mxl files cannot be loaded by Lomse.

The reason of the issue is that the implementation in #246 loads unzipped XML code via MxlCompiler::compile_string() function which internally calls load_string() function from pugixml which assumes the string is already encoded in UTF-8. However the example scores listed above use UTF-16 encoding which is incompatible with UTF-8. File loading functions in pugixml do not assume any encoding by default and perform encoding detection which is why the uncompressed versions of the example scores are loaded correctly.

The issue can be fixed by using pugixml's load_buffer() which takes an in-memory buffer as input and doesn't skip encoding detection. This solution is implemented in this pull request. After this patch any encoding supported by pugixml should work fine with both compressed and uncompressed MusicXML files.

cecilios commented 3 years ago

Thank you. I will review this as soon as possible.

cecilios commented 3 years ago

The code changes look OK to me and no issues detected in tests. Merging. Thank you very much!