[FFmpeg-devel,4/4] avcodec/fitsdec: Check data_min/max

Submitted by Michael Niedermayer on June 12, 2019, 11:20 p.m.

Details

Message ID 20190612232020.25959-4-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer June 12, 2019, 11:20 p.m.
Fixes: division by 0
Fixes: 15206/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FITS_fuzzer-5657260212092928

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/fitsdec.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Moritz Barsnick June 13, 2019, 2:29 p.m.
On Thu, Jun 13, 2019 at 01:20:20 +0200, Michael Niedermayer wrote:
> +        if (header->data_min == header->data_max) {

Just a note:
Equality comparison of floats/doubles may trigger a warning. (Possibly
needs to be explicitly enabled though, like with "-Wfloat-equal" on
gcc.) Might be okay though nevertheless.

Moritz
Michael Niedermayer June 25, 2019, 9:43 a.m.
On Thu, Jun 13, 2019 at 04:29:54PM +0200, Moritz Barsnick wrote:
> On Thu, Jun 13, 2019 at 01:20:20 +0200, Michael Niedermayer wrote:
> > +        if (header->data_min == header->data_max) {
> 
> Just a note:
> Equality comparison of floats/doubles may trigger a warning. (Possibly
> needs to be explicitly enabled though, like with "-Wfloat-equal" on
> gcc.) Might be okay though nevertheless.

ill post a new patch that reorders this a bit, maybe it doesnt generate
a warning. But using something like DBL_EPSILON is more wrong than the ==
here i think, as it could turn a non blank image into a blank one

thx


[...]

Patch hide | download patch | download mbox

diff --git a/libavcodec/fitsdec.c b/libavcodec/fitsdec.c
index b0753813c9..2da79e1ef9 100644
--- a/libavcodec/fitsdec.c
+++ b/libavcodec/fitsdec.c
@@ -168,6 +168,16 @@  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) {
+        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;
+        }
+        if (header->data_min == header->data_max) {
+            av_log(avctx, AV_LOG_WARNING, "data min/max indicates a blank image\n");
+            header->data_max ++;
+        }
+    }
 
     return 0;
 }