diff --git a/libavcodec/aacsbr_fixed.c b/libavcodec/aacsbr_fixed.c
index 269c9a2c881cf7ab708c228ce6bd235338d37089..2531637194b051ce0b18ef39950d2b96fc71e677 100644
--- a/libavcodec/aacsbr_fixed.c
+++ b/libavcodec/aacsbr_fixed.c
@@ -575,22 +575,30 @@ static void sbr_hf_assemble(int Y1[38][64][2],
 
                 SoftFloat *in  = sbr->s_m[e];
                 for (m = 0; m+1 < m_max; m+=2) {
+                    int shift2;
                     shift = 22 - in[m  ].exp;
+                    shift2= 22 - in[m+1].exp;
+                    if (shift < 1 || shift2 < 1) {
+                        av_log(NULL, AV_LOG_ERROR, "Overflow in sbr_hf_assemble, shift=%d,%d\n", shift, shift2);
+                        return;
+                    }
                     if (shift < 32) {
                         round = 1 << (shift-1);
                         out[2*m  ] += (in[m  ].mant * A + round) >> shift;
                     }
 
-                    shift = 22 - in[m+1].exp;
-                    if (shift < 32) {
-                        round = 1 << (shift-1);
-                        out[2*m+2] += (in[m+1].mant * B + round) >> shift;
+                    if (shift2 < 32) {
+                        round = 1 << (shift2-1);
+                        out[2*m+2] += (in[m+1].mant * B + round) >> shift2;
                     }
                 }
                 if(m_max&1)
                 {
                     shift = 22 - in[m  ].exp;
-                    if (shift < 32) {
+                    if (shift < 1) {
+                        av_log(NULL, AV_LOG_ERROR, "Overflow in sbr_hf_assemble, shift=%d\n", shift);
+                        return;
+                    } else if (shift < 32) {
                         round = 1 << (shift-1);
                         out[2*m  ] += (in[m  ].mant * A + round) >> shift;
                     }