libOpus: fix integer overflow in silk_resampler_down2_hp
Bug: 190882774
Test: poc in bug description
Change-Id: Ib780a7d3e114ed29047c50459c01462c6b244f31
diff --git a/src/analysis.c b/src/analysis.c
index 058328f..8b4f22d 100644
--- a/src/analysis.c
+++ b/src/analysis.c
@@ -149,7 +149,10 @@
out32_hp = ADD32( out32_hp, X );
S[ 2 ] = ADD32( -in32, X );
- hp_ener += out32_hp*(opus_val64)out32_hp;
+ if(__builtin_add_overflow(hp_ener, out32_hp*(opus_val64)out32_hp, &hp_ener))
+ {
+ hp_ener = UINT64_MAX;
+ }
/* Add, convert back to int16 and store to output */
out[ k ] = HALF32(out32);
}