Merge commit '9f732e4c996243c1e57c2bbbec6c8b94c37a7a22'
authorHendrik Leppkes <h.leppkes@gmail.com>
Mon, 14 Nov 2016 11:30:35 +0000 (12:30 +0100)
committerHendrik Leppkes <h.leppkes@gmail.com>
Mon, 14 Nov 2016 11:30:35 +0000 (12:30 +0100)
* commit '9f732e4c996243c1e57c2bbbec6c8b94c37a7a22':
  tiffenc: Check av_pix_fmt_desc_get() return value

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
1  2 
libavcodec/tiffenc.c

@@@ -265,32 -246,37 +265,35 @@@ static int encode_frame(AVCodecContext 
      s->subsampling[0] = 1;
      s->subsampling[1] = 1;
  
++    if (!desc)
++        return AVERROR(EINVAL);
++
 +    avctx->bits_per_coded_sample =
 +    s->bpp          = av_get_bits_per_pixel(desc);
 +    s->bpp_tab_size = desc->nb_components;
 +
      switch (avctx->pix_fmt) {
      case AV_PIX_FMT_RGBA64LE:
 -    case AV_PIX_FMT_RGB48LE:
 -    case AV_PIX_FMT_GRAY16LE:
      case AV_PIX_FMT_RGBA:
 +        alpha = 1;
 +    case AV_PIX_FMT_RGB48LE:
      case AV_PIX_FMT_RGB24:
 -    case AV_PIX_FMT_GRAY8:
 -    case AV_PIX_FMT_PAL8:
 -        pfd = av_pix_fmt_desc_get(avctx->pix_fmt);
 -        if (!pfd)
 -            return AVERROR_BUG;
 -        s->bpp = av_get_bits_per_pixel(pfd);
 -        if (pfd->flags & AV_PIX_FMT_FLAG_PAL)
 -            s->photometric_interpretation = TIFF_PHOTOMETRIC_PALETTE;
 -        else if (pfd->flags & AV_PIX_FMT_FLAG_RGB)
 -            s->photometric_interpretation = TIFF_PHOTOMETRIC_RGB;
 -        else
 -            s->photometric_interpretation = TIFF_PHOTOMETRIC_BLACK_IS_ZERO;
 -        s->bpp_tab_size = pfd->nb_components;
 -        for (i = 0; i < s->bpp_tab_size; i++)
 -            bpp_tab[i] = s->bpp / s->bpp_tab_size;
 +        s->photometric_interpretation = TIFF_PHOTOMETRIC_RGB;
          break;
 +    case AV_PIX_FMT_GRAY8:
 +        avctx->bits_per_coded_sample = 0x28;
 +    case AV_PIX_FMT_GRAY8A:
 +    case AV_PIX_FMT_YA16LE:
 +        alpha = avctx->pix_fmt == AV_PIX_FMT_GRAY8A || avctx->pix_fmt == AV_PIX_FMT_YA16LE;
 +    case AV_PIX_FMT_GRAY16LE:
      case AV_PIX_FMT_MONOBLACK:
 -        s->bpp                        = 1;
          s->photometric_interpretation = TIFF_PHOTOMETRIC_BLACK_IS_ZERO;
 -        s->bpp_tab_size               = 0;
 +        break;
 +    case AV_PIX_FMT_PAL8:
 +        s->photometric_interpretation = TIFF_PHOTOMETRIC_PALETTE;
          break;
      case AV_PIX_FMT_MONOWHITE:
 -        s->bpp                        = 1;
          s->photometric_interpretation = TIFF_PHOTOMETRIC_WHITE_IS_ZERO;
 -        s->bpp_tab_size               = 0;
          break;
      case AV_PIX_FMT_YUV420P:
      case AV_PIX_FMT_YUV422P: