Skip to content

Commit

Permalink
Avoid num_samples from becoming negative (FluidSynth#653)
Browse files Browse the repository at this point in the history
For Soundfonts bigger 2GiB, num_samples becomes negative. When being passed to safe_fread() it's promoted to long long and when being passed to fread(), it's cast to size_t. Works fine in twos-complement, but still is not nice.
  • Loading branch information
derselbst authored Jun 8, 2020
1 parent 0354196 commit e16ca05
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/sfloader/fluid_sffile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2379,9 +2379,11 @@ static int fluid_sffile_read_wav(SFData *sf, unsigned int start, unsigned int en
{
short *loaded_data = NULL;
char *loaded_data24 = NULL;
unsigned int num_samples;

int num_samples = (end + 1) - start;
fluid_return_val_if_fail(num_samples > 0, -1);
fluid_return_val_if_fail((end + 1) > start , -1);

num_samples = (end + 1) - start;

if((start * sizeof(short) > sf->samplesize) || (end * sizeof(short) > sf->samplesize))
{
Expand Down Expand Up @@ -2413,7 +2415,7 @@ static int fluid_sffile_read_wav(SFData *sf, unsigned int start, unsigned int en
/* If this machine is big endian, byte swap the 16 bit samples */
if(FLUID_IS_BIG_ENDIAN)
{
int i;
unsigned int i;

for(i = 0; i < num_samples; i++)
{
Expand Down

0 comments on commit e16ca05

Please sign in to comment.