OSDN Git Service

Prevent integer overflow
authorStarg <starg@users.osdn.me>
Thu, 22 Feb 2018 16:22:51 +0000 (01:22 +0900)
committerStarg <starg@users.osdn.me>
Thu, 22 Feb 2018 16:22:51 +0000 (01:22 +0900)
timidity/mod2midi.c
timidity/playmidi.c
timidity/resample.c
timidity/smplfile.c

index 45253bf..ee31aea 100644 (file)
@@ -601,7 +601,7 @@ void shrink_huge_sample (Sample *sp)
     sp->data = new_data;
     sp->sample_rate = new_rate;
 
-    sp->data_length = new_data_length << FRACTION_BITS;
+    sp->data_length = (splen_t)new_data_length << FRACTION_BITS;
     sp->loop_start = loop_start * (1 << FRACTION_BITS);
     sp->loop_end = loop_end * (1 << FRACTION_BITS);
 }
index 7d3d82c..71e0112 100644 (file)
@@ -4486,7 +4486,7 @@ static void start_note(MidiEvent *e, int i, int vid, int cnt, int add_delay_cnt)
                if(!special_patch[j]){
                        vp->reserve_offset = 0;
                }else{
-                       vp->reserve_offset = special_patch[j]->sample_offset << FRACTION_BITS;
+                       vp->reserve_offset = (splen_t)special_patch[j]->sample_offset << FRACTION_BITS;
                        if(vp->sample->modes & MODES_LOOPING)  {
                                if(vp->reserve_offset > vp->sample->loop_end)
                                        vp->reserve_offset = vp->sample->loop_start;
index 0ec0391..967a930 100644 (file)
@@ -5090,7 +5090,7 @@ void resample_voice(int v, DATA_T *ptr, int32 count)
                        /* Let the caller know how much data we had left */
                        count2 = (int32)((vp->sample->data_length >> FRACTION_BITS) - ofs);
                }else
-                       vp->resrc.offset += (count2 << FRACTION_BITS);
+                       vp->resrc.offset += ((splen_t)count2 << FRACTION_BITS);
 
                switch(vp->sample->data_type){
                case SAMPLE_TYPE_INT16:
index 48b4a55..aba6569 100755 (executable)
@@ -477,7 +477,7 @@ static int import_wave_load(char *sample_file, Instrument *inst)
        {
                uint8  modes;
                int32  sample_rate, root_freq;
-               uint32 loopStart = 0, loopEnd = 0;
+               splen_t loopStart = 0, loopEnd = 0;
 
                sample_rate = samplerc.dwSamplePeriod == 0 ? 0 : 1000000000L / samplerc.dwSamplePeriod;
                root_freq = freq_table[samplerc.dwMIDIUnityNote];
@@ -494,8 +494,8 @@ static int import_wave_load(char *sample_file, Instrument *inst)
                        const uint8 loopModes[] = { MODES_LOOPING, MODES_LOOPING | MODES_PINGPONG, MODES_LOOPING | MODES_REVERSE };
 
                        modes = loopModes[samplerc.loopType];
-                       loopStart = samplerc.loop_dwStart << FRACTION_BITS;
-                       loopEnd = samplerc.loop_dwEnd << FRACTION_BITS;
+                       loopStart = (splen_t)samplerc.loop_dwStart << FRACTION_BITS;
+                       loopEnd = (splen_t)samplerc.loop_dwEnd << FRACTION_BITS;
                }
                else
                        modes = 0;
@@ -1294,7 +1294,7 @@ static void initialize_sample(Instrument *inst, int frames, int sample_bits, int
                sample = &inst->sample[i];
                sample->data_alloced = 0;
                sample->loop_start = 0;
-               sample->loop_end = sample->data_length = frames << FRACTION_BITS;
+               sample->loop_end = sample->data_length = (splen_t)frames << FRACTION_BITS;
                sample->sample_rate = sample_rate;
                sample->low_key = 0;
                sample->high_key = 127;