diff mbox

[FFmpeg-devel] avcodec/fitsdec: fix use of uninitialised values

Message ID 20190929021208.47403-1-jamrial@gmail.com
State Accepted
Commit e3f0ecfc57889de0e0a359ec30b77851d53cea87
Headers show

Commit Message

James Almer Sept. 29, 2019, 2:12 a.m. UTC
header.data_max and header.data_min are not necessarely set on all decoding scenarios.

Fixes a Valgrind reported regression since cfa193779103c97bbfc28273a0ab12c114b6786d.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/fitsdec.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Michael Niedermayer Sept. 29, 2019, 3:38 p.m. UTC | #1
On Sat, Sep 28, 2019 at 11:12:08PM -0300, James Almer wrote:
> header.data_max and header.data_min are not necessarely set on all decoding scenarios.
> 
> Fixes a Valgrind reported regression since cfa193779103c97bbfc28273a0ab12c114b6786d.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/fitsdec.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)

LGTM

thx

[...]
James Almer Sept. 29, 2019, 3:50 p.m. UTC | #2
On 9/29/2019 12:38 PM, Michael Niedermayer wrote:
> On Sat, Sep 28, 2019 at 11:12:08PM -0300, James Almer wrote:
>> header.data_max and header.data_min are not necessarely set on all decoding scenarios.
>>
>> Fixes a Valgrind reported regression since cfa193779103c97bbfc28273a0ab12c114b6786d.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  libavcodec/fitsdec.c | 14 +++++++-------
>>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> LGTM
> 
> thx

Pushed.
diff mbox

Patch

diff --git a/libavcodec/fitsdec.c b/libavcodec/fitsdec.c
index 88b841a964..a20b8faf9e 100644
--- a/libavcodec/fitsdec.c
+++ b/libavcodec/fitsdec.c
@@ -195,7 +195,6 @@  static int fits_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     uint8_t *dst8;
     uint16_t *dst16;
     uint64_t t;
-    double scale;
     FITSHeader header;
     FITSContext * fitsctx = avctx->priv_data;
 
@@ -205,12 +204,6 @@  static int fits_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     if (ret < 0)
         return ret;
 
-    scale = header.data_max - header.data_min;
-    if (scale <= 0 || !isfinite(scale)) {
-        scale = 1;
-    }
-    scale = 1/scale;
-
     if (header.rgb) {
         if (header.bitpix == 8) {
             if (header.naxisn[2] == 3) {
@@ -271,6 +264,13 @@  static int fits_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
             CASE_RGB(16, dst16, uint16_t, AV_RB16);
         }
     } else {
+        double scale = header.data_max - header.data_min;
+
+        if (scale <= 0 || !isfinite(scale)) {
+            scale = 1;
+        }
+        scale = 1/scale;
+
         switch (header.bitpix) {
 #define CASE_GRAY(cas, dst, type, t, rd) \
     case cas: \