diff mbox series

[FFmpeg-devel,3/5] mlpenc: prevent negative lsb_bits lshift

Message ID 20200124103334.110855-4-me@jailuthra.in
State Accepted
Headers show
Series mlpenc: fix lossless check failures for 16-bit encoding
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Jai Luthra Jan. 24, 2020, 10:33 a.m. UTC
Fixes Coverity CID 1396239.

Signed-off-by: Jai Luthra <me@jailuthra.in>
---
 libavcodec/mlpenc.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
index 1cee38c82f..41030f6f07 100644
--- a/libavcodec/mlpenc.c
+++ b/libavcodec/mlpenc.c
@@ -1,6 +1,7 @@ 
 /**
  * MLP encoder
  * Copyright (c) 2008 Ramiro Polla
+ * Copyright (c) 2016-2019 Jai Luthra
  *
  * This file is part of FFmpeg.
  *
@@ -1562,7 +1563,7 @@  static void no_codebook_bits_offset(MLPEncodeContext *ctx,
                                     BestOffset *bo)
 {
     DecodingParams *dp = ctx->cur_decoding_params;
-    int32_t unsign;
+    int32_t unsign = 0;
     int lsb_bits;
 
     min -= offset;
@@ -1572,7 +1573,8 @@  static void no_codebook_bits_offset(MLPEncodeContext *ctx,
 
     lsb_bits += !!lsb_bits;
 
-    unsign = 1 << (lsb_bits - 1);
+    if (lsb_bits > 0)
+        unsign = 1 << (lsb_bits - 1);
 
     bo->offset   = offset;
     bo->lsb_bits = lsb_bits;
@@ -1591,7 +1593,7 @@  static void no_codebook_bits(MLPEncodeContext *ctx,
 {
     DecodingParams *dp = ctx->cur_decoding_params;
     int16_t offset;
-    int32_t unsign;
+    int32_t unsign = 0;
     uint32_t diff;
     int lsb_bits;
 
@@ -1607,7 +1609,8 @@  static void no_codebook_bits(MLPEncodeContext *ctx,
 
     lsb_bits = number_sbits(diff) - 1;
 
-    unsign = 1 << (lsb_bits - 1);
+    if (lsb_bits > 0)
+        unsign = 1 << (lsb_bits - 1);
 
     /* If all samples are the same (lsb_bits == 0), offset must be
      * adjusted because of sign_shift. */