chipweinberger / dart_melty_soundfont

A port of Melty Synth by Nobuaki Tanaka (C#) to Dart
Other
33 stars 8 forks source link

Potential issue with file I/O #19

Closed sinshu closed 1 year ago

sinshu commented 1 year ago

Hi.

I have discovered a potential issue in the C# version. For instance, in the constructor of SoundFontParameters, the variable end was calculated as follows:

var end = reader.BaseStream.Position + reader.ReadInt32();

In this case, end would end up being 4 bytes smaller than the desired value. Ideally, end should be calculated after the completion of ReadInt32():

var end = (long)reader.ReadInt32();
end += reader.BaseStream.Position;

There are also several similar pieces of code beyond SoundFontParameters. I suspect that there are very few SoundFonts that would cause this to be an issue, but I wanted to report this just in case.

chipweinberger commented 1 year ago

@sinshu I appreciate you taking the time to file this issue. It means a lot that you care to help! ❤️

Yes it appears I have the same mistake:

mistake:

    factory SoundFontParameters.fromReader(BinaryReader reader)  {
        ...
        int end = reader.pos + reader.readInt32();
        ...
     }

should be:

    factory SoundFontParameters.fromReader(BinaryReader reader)  {
        ...
        int end = reader.readInt32();
        end += reader.pos;
        ...
     }

I will fix the code.

chipweinberger commented 1 year ago

I see the same mistakes you fixed are here: https://github.com/sinshu/meltysynth/commit/ebc0b9126bc5d193a7851c38b0d13f3cb79952d1

chipweinberger commented 1 year ago

fixed https://github.com/chipweinberger/dart_melty_soundfont/commit/935bb89dab5567cad7f48b49ccb6aad1f3664719