OSDN Git Service

Fix resample buffer overrun
authorStarg <starg@users.osdn.me>
Sun, 2 Aug 2020 09:25:09 +0000 (18:25 +0900)
committerStarg <starg@users.osdn.me>
Sun, 2 Aug 2020 09:25:09 +0000 (18:25 +0900)
timidity/resample.c

index 41f1673..8fc17f5 100644 (file)
@@ -4616,7 +4616,7 @@ static void lo_rs_plain(Voice *vp, DATA_T *dest, int32 count)
        int32 i = 0, j;
 
        if (resrc->increment < 0) resrc->increment = -resrc->increment; /* In case we're coming out of a bidir loop */
-       j = PRECALC_LOOP_COUNT(resrc->offset, resrc->data_length, resrc->increment) + 2; // safe end+128 sample
+       j = PRECALC_LOOP_COUNT(resrc->offset, resrc->data_length, resrc->increment) - 2; // safe end+128 sample
        if (j > count) {j = count;}
        else if(j < 0) {j = 0;} 
        dest = resample_linear_multi(vp, dest, j, &i);
@@ -4804,7 +4804,7 @@ static void lo_rs_plain_float(Voice *vp, DATA_T *dest, int32 count)
        int32 i = 0, j;
 
        if (resrc->increment < 0) resrc->increment = -resrc->increment; /* In case we're coming out of a bidir loop */
-       j = PRECALC_LOOP_COUNT(resrc->offset, resrc->data_length, resrc->increment) + 2; // safe end+128 sample
+       j = PRECALC_LOOP_COUNT(resrc->offset, resrc->data_length, resrc->increment) - 2; // safe end+128 sample
        if (j > count) {j = count;}
        else if(j < 0) {j = 0;} 
        dest = resample_linear_float_multi(vp, dest, j, &i);
@@ -5683,7 +5683,7 @@ static void lao_rs_plain(Voice *vp, DATA_T *dest, int32 count)
        int32 i = 0, j = 0;     
        
        if (resrc->increment < 0) resrc->increment = -resrc->increment; /* In case we're coming out of a bidir loop */
-       j = PRECALC_LOOP_COUNT(resrc->offset, resrc->data_length, resrc->increment) + 4; // safe end+128 sample
+       j = PRECALC_LOOP_COUNT(resrc->offset, resrc->data_length, resrc->increment) - 4; // safe end+128 sample
        if (j > count) {j = count;}
        else if(j < 0) {j = 0;} 
        if((resrc->offset >> FRACTION_BITS) >= 1)
@@ -6070,7 +6070,7 @@ static void lao_rs_plain_float(Voice *vp, DATA_T *dest, int32 count)
        int32 i = 0, j = 0;     
        
        if (resrc->increment < 0) resrc->increment = -resrc->increment; /* In case we're coming out of a bidir loop */
-       j = PRECALC_LOOP_COUNT(resrc->offset, resrc->data_length, resrc->increment) + 4; // safe end+128 sample
+       j = PRECALC_LOOP_COUNT(resrc->offset, resrc->data_length, resrc->increment) - 4; // safe end+128 sample
        if (j > count) {j = count;}
        else if(j < 0) {j = 0;} 
        if((resrc->offset >> FRACTION_BITS) >= 1)