]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/fitsdec.c
libavformat/rtsp: return error if rtsp_hd_out is null instead of crash
[ffmpeg] / libavcodec / fitsdec.c
index b0753813c9c92419b6318d5787b13132f1fbc19f..88b841a964453fd7ed5988becc7c3edbae1643ac 100644 (file)
@@ -143,7 +143,7 @@ static int fits_read_header(AVCodecContext *avctx, const uint8_t **ptr, FITSHead
 
     size = abs(header->bitpix) >> 3;
     for (i = 0; i < header->naxis; i++) {
-        if (header->naxisn[i] > SIZE_MAX / size) {
+        if (size && header->naxisn[i] > SIZE_MAX / size) {
             av_log(avctx, AV_LOG_ERROR, "unsupported size of FITS image");
             return AVERROR_INVALIDDATA;
         }
@@ -168,6 +168,14 @@ static int fits_read_header(AVCodecContext *avctx, const uint8_t **ptr, FITSHead
         header->data_min = (header->data_min - header->bzero) / header->bscale;
         header->data_max = (header->data_max - header->bzero) / header->bscale;
     }
+    if (!header->rgb && header->data_min >= header->data_max) {
+        if (header->data_min > header->data_max) {
+            av_log(avctx, AV_LOG_ERROR, "data min/max (%g %g) is invalid\n", header->data_min, header->data_max);
+            return AVERROR_INVALIDDATA;
+        }
+        av_log(avctx, AV_LOG_WARNING, "data min/max indicates a blank image\n");
+        header->data_max ++;
+    }
 
     return 0;
 }
@@ -187,6 +195,7 @@ 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;
 
@@ -196,6 +205,12 @@ 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) {
@@ -264,7 +279,7 @@ static int fits_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
             for (j = 0; j < avctx->width; j++) { \
                 t = rd; \
                 if (!header.blank_found || t != header.blank) { \
-                    *dst++ = ((t - header.data_min) * ((1 << (sizeof(type) * 8)) - 1)) / (header.data_max - header.data_min); \
+                    *dst++ = ((t - header.data_min) * ((1 << (sizeof(type) * 8)) - 1)) * scale; \
                 } else { \
                     *dst++ = fitsctx->blank_val; \
                 } \