sinshu / rustysynth

A SoundFont MIDI synthesizer written in pure Rust
Other
139 stars 22 forks source link

fix: Use `read_u32` instead of `read_i32` to prevent wrong size parsing #12

Closed paxbun closed 1 year ago

paxbun commented 1 year ago

The current code fails to parse SoundFonts greater than 2GB, because of code like the following:

https://github.com/sinshu/rustysynth/blob/b87a7f2329c049eb22f6345fb8e6a88b8528f5f1/rustysynth/src/soundfont_sampledata.rs#L23

When the size of the chunk is greater than 2GB, which makes the MSB be set, the resulting usize contains a value like 0xFFFFFFFF..., due to the sign extension.

This PR adds BinaryReader::read_u32 to prevent this. This PR also adds the type FourCC so BinaryReader::read_four_cc does not allocate a String redundantly.

Please refer to the following for more details in the numeric cast in Rust:

sinshu commented 1 year ago

Thanks 😄 Your PR looks good. I'll test the code this weekend.

sinshu commented 1 year ago

I merged the PR. It's nice that the error types don't allocate a String 😎👍