X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Ffitsdec.c;h=54412c60ff861418859e5732d040d564bc84ee66;hb=3a3e8c35b63a40c4d59161097dc8652c15d13779;hp=4b288b3903939f01c8c4e6c25e9a50b721ae4b1a;hpb=1a8be90adbaf86faa3053ff98118004ad7711c8c;p=ffmpeg diff --git a/libavformat/fitsdec.c b/libavformat/fitsdec.c index 4b288b39039..54412c60ff8 100644 --- a/libavformat/fitsdec.c +++ b/libavformat/fitsdec.c @@ -24,6 +24,7 @@ * FITS demuxer. */ +#include "libavutil/avassert.h" #include "libavutil/intreadwrite.h" #include "internal.h" #include "libavutil/opt.h" @@ -39,7 +40,7 @@ typedef struct FITSContext { int64_t pts; } FITSContext; -static int fits_probe(AVProbeData *p) +static int fits_probe(const AVProbeData *p) { const uint8_t *b = p->buf; if (!memcmp(b, "SIMPLE = T", 30)) @@ -125,14 +126,14 @@ static int64_t is_image(AVFormatContext *s, FITSContext *fits, FITSHeader *heade size += header->pcount; t = (abs(header->bitpix) >> 3) * ((int64_t) header->gcount); - if(size && t > UINT64_MAX / size) + if(size && t > INT64_MAX / size) return AVERROR_INVALIDDATA; size *= t; if (!size) { image = 0; } else { - if(FITS_BLOCK_SIZE - 1 > UINT64_MAX - size) + if(FITS_BLOCK_SIZE - 1 > INT64_MAX - size) return AVERROR_INVALIDDATA; size = ((size + FITS_BLOCK_SIZE - 1) / FITS_BLOCK_SIZE) * FITS_BLOCK_SIZE; } @@ -157,11 +158,11 @@ static int fits_read_packet(AVFormatContext *s, AVPacket *pkt) av_bprint_init(&avbuf, FITS_BLOCK_SIZE, AV_BPRINT_SIZE_UNLIMITED); while ((ret = is_image(s, fits, &header, &avbuf, &size)) == 0) { + av_bprint_finalize(&avbuf, NULL); pos = avio_skip(s->pb, size); if (pos < 0) return pos; - av_bprint_finalize(&avbuf, NULL); av_bprint_init(&avbuf, FITS_BLOCK_SIZE, AV_BPRINT_SIZE_UNLIMITED); avpriv_fits_header_init(&header, STATE_XTENSION); } @@ -173,6 +174,11 @@ static int fits_read_packet(AVFormatContext *s, AVPacket *pkt) goto fail; } + av_assert0(avbuf.len <= INT64_MAX && size <= INT64_MAX); + if (avbuf.len + size > INT_MAX - 80) { + ret = AVERROR_INVALIDDATA; + goto fail; + } // Header is sent with the first line removed... ret = av_new_packet(pkt, avbuf.len - 80 + size); if (ret < 0) @@ -183,7 +189,6 @@ static int fits_read_packet(AVFormatContext *s, AVPacket *pkt) ret = av_bprint_finalize(&avbuf, &buf); if (ret < 0) { - av_packet_unref(pkt); return ret; } @@ -192,7 +197,6 @@ static int fits_read_packet(AVFormatContext *s, AVPacket *pkt) av_freep(&buf); ret = avio_read(s->pb, pkt->data + pkt->size, size); if (ret < 0) { - av_packet_unref(pkt); return ret; } @@ -219,7 +223,7 @@ static const AVClass fits_demuxer_class = { .version = LIBAVUTIL_VERSION_INT, }; -AVInputFormat ff_fits_demuxer = { +const AVInputFormat ff_fits_demuxer = { .name = "fits", .long_name = NULL_IF_CONFIG_SMALL("Flexible Image Transport System"), .priv_data_size = sizeof(FITSContext),