|
36 | 36 | #include "reverb.h" |
37 | 37 | #include "sample.h" |
38 | 38 |
|
| 39 | +/* Smallest float that does NOT fit in a uint32_t (2^32); used to reject an |
| 40 | + * out-of-range sample count before the float->uint32 conversion. */ |
| 41 | +#define WM_TWO_TO_32_F 4294967296.0f |
39 | 42 |
|
40 | 43 | struct _mdi * |
41 | 44 | _WM_ParseNewMidi(const uint8_t *midi_data, uint32_t midi_size) { |
@@ -247,7 +250,7 @@ _WM_ParseNewMidi(const uint8_t *midi_data, uint32_t midi_size) { |
247 | 250 |
|
248 | 251 | subtract_delta = smallest_delta; |
249 | 252 | sample_count_f = (((float) smallest_delta * samples_per_delta_f) + sample_remainder); |
250 | | - if (sample_count_f < 0.0f || sample_count_f >= 4294967296.0f) { _WM_GLOBAL_ERROR(WM_ERR_CORUPT, "sample count out of range", 0); goto _end; } sample_count = (uint32_t) sample_count_f; |
| 253 | + if (sample_count_f < 0.0f || sample_count_f >= WM_TWO_TO_32_F) { _WM_GLOBAL_ERROR(WM_ERR_CORUPT, "sample count out of range", 0); goto _end; } sample_count = (uint32_t) sample_count_f; |
251 | 254 | sample_remainder = sample_count_f - (float) sample_count; |
252 | 255 |
|
253 | 256 | mdi->events[mdi->event_count - 1].samples_to_next += sample_count; |
@@ -345,7 +348,7 @@ _WM_ParseNewMidi(const uint8_t *midi_data, uint32_t midi_size) { |
345 | 348 | subtract_delta = smallest_delta; |
346 | 349 | sample_count_f = (((float) smallest_delta * samples_per_delta_f) |
347 | 350 | + sample_remainder); |
348 | | - if (sample_count_f < 0.0f || sample_count_f >= 4294967296.0f) { _WM_GLOBAL_ERROR(WM_ERR_CORUPT, "sample count out of range", 0); goto _end; } sample_count = (uint32_t) sample_count_f; |
| 351 | + if (sample_count_f < 0.0f || sample_count_f >= WM_TWO_TO_32_F) { _WM_GLOBAL_ERROR(WM_ERR_CORUPT, "sample count out of range", 0); goto _end; } sample_count = (uint32_t) sample_count_f; |
349 | 352 | sample_remainder = sample_count_f - (float) sample_count; |
350 | 353 |
|
351 | 354 | mdi->events[mdi->event_count - 1].samples_to_next += sample_count; |
@@ -418,7 +421,7 @@ _WM_ParseNewMidi(const uint8_t *midi_data, uint32_t midi_size) { |
418 | 421 | } |
419 | 422 | sample_count_f = (((float) track_delta[i] * samples_per_delta_f) |
420 | 423 | + sample_remainder); |
421 | | - if (sample_count_f < 0.0f || sample_count_f >= 4294967296.0f) { _WM_GLOBAL_ERROR(WM_ERR_CORUPT, "sample count out of range", 0); goto _end; } sample_count = (uint32_t) sample_count_f; |
| 424 | + if (sample_count_f < 0.0f || sample_count_f >= WM_TWO_TO_32_F) { _WM_GLOBAL_ERROR(WM_ERR_CORUPT, "sample count out of range", 0); goto _end; } sample_count = (uint32_t) sample_count_f; |
422 | 425 | sample_remainder = sample_count_f - (float) sample_count; |
423 | 426 | mdi->events[mdi->event_count - 1].samples_to_next += sample_count; |
424 | 427 | mdi->extra_info.approx_total_samples += sample_count; |
|
0 commit comments