libavcodec/flac_parser.c:97: error: Null Dereference
  pointer `&gb->buffer` last assigned on line 96 could be null and is dereferenced by call to `ff_flac_decode_frame_header()` at line 97, column 13.

libavcodec/flac_parser.c:92:1: start of procedure frame_header_is_valid()
90. } FLACParseContext;
91. 
92. static int frame_header_is_valid(AVCodecContext *avctx, const uint8_t *buf,
    ^
93.                                  FLACFrameInfo *fi)
94. {

libavcodec/flac_parser.c:96:5: 
94. {
95.     GetBitContext gb;
96.     init_get_bits(&gb, buf, MAX_FRAME_HEADER_SIZE * 8);
        ^
97.     return !ff_flac_decode_frame_header(avctx, &gb, fi, 127);
98. }

libavcodec/get_bits.h:362:1: start of procedure init_get_bits()
  360.  * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
  361.  */
  362. static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,
       ^
  363.                                 int bit_size)
  364. {

libavcodec/get_bits.h:366:5: 
  364. {
  365.     int buffer_size;
  366.     int ret = 0;
           ^
  367. 
  368.     if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {

libavcodec/get_bits.h:368:9: Taking false branch
  366.     int ret = 0;
  367. 
  368.     if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {
               ^
  369.         bit_size    = 0;
  370.         buffer      = NULL;

libavcodec/get_bits.h:368:35: Taking false branch
  366.     int ret = 0;
  367. 
  368.     if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {
                                         ^
  369.         bit_size    = 0;
  370.         buffer      = NULL;

libavcodec/get_bits.h:368:52: Taking true branch
  366.     int ret = 0;
  367. 
  368.     if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {
                                                          ^
  369.         bit_size    = 0;
  370.         buffer      = NULL;

libavcodec/get_bits.h:369:9: 
  367. 
  368.     if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {
  369.         bit_size    = 0;
               ^
  370.         buffer      = NULL;
  371.         ret         = AVERROR_INVALIDDATA;

libavcodec/get_bits.h:370:9: 
  368.     if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {
  369.         bit_size    = 0;
  370.         buffer      = NULL;
               ^
  371.         ret         = AVERROR_INVALIDDATA;
  372.     }

libavcodec/get_bits.h:371:9: 
  369.         bit_size    = 0;
  370.         buffer      = NULL;
  371.         ret         = AVERROR_INVALIDDATA;
               ^
  372.     }
  373. 

libavcodec/get_bits.h:374:5: 
  372.     }
  373. 
  374.     buffer_size = (bit_size + 7) >> 3;
           ^
  375. 
  376.     s->buffer             = buffer;

libavcodec/get_bits.h:376:5: 
  374.     buffer_size = (bit_size + 7) >> 3;
  375. 
  376.     s->buffer             = buffer;
           ^
  377.     s->size_in_bits       = bit_size;
  378. #if !UNCHECKED_BITSTREAM_READER

libavcodec/get_bits.h:377:5: 
  375. 
  376.     s->buffer             = buffer;
  377.     s->size_in_bits       = bit_size;
           ^
  378. #if !UNCHECKED_BITSTREAM_READER
  379.     s->size_in_bits_plus8 = bit_size + 8;

libavcodec/get_bits.h:379:5: 
  377.     s->size_in_bits       = bit_size;
  378. #if !UNCHECKED_BITSTREAM_READER
  379.     s->size_in_bits_plus8 = bit_size + 8;
           ^
  380. #endif
  381.     s->buffer_end         = buffer + buffer_size;

libavcodec/get_bits.h:381:5: 
  379.     s->size_in_bits_plus8 = bit_size + 8;
  380. #endif
  381.     s->buffer_end         = buffer + buffer_size;
           ^
  382.     s->index              = 0;
  383. 

libavcodec/get_bits.h:382:5: 
  380. #endif
  381.     s->buffer_end         = buffer + buffer_size;
  382.     s->index              = 0;
           ^
  383. 
  384.     return ret;

libavcodec/get_bits.h:384:5: 
  382.     s->index              = 0;
  383. 
  384.     return ret;
           ^
  385. }
  386. 

libavcodec/get_bits.h:385:1: return from a call to init_get_bits
  383. 
  384.     return ret;
  385. }
       ^
  386. 
  387. /**

libavcodec/flac_parser.c:97:13: 
95.     GetBitContext gb;
96.     init_get_bits(&gb, buf, MAX_FRAME_HEADER_SIZE * 8);
97.     return !ff_flac_decode_frame_header(avctx, &gb, fi, 127);
                ^
98. }
99. 

libavcodec/flac.c:50:1: start of procedure ff_flac_decode_frame_header()
  48. }
  49. 
  50. int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
      ^
  51.                                 FLACFrameInfo *fi, int log_level_offset)
  52. {

libavcodec/flac.c:56:9: Taking false branch
  54. 
  55.     /* frame sync code */
  56.     if ((get_bits(gb, 15) & 0x7FFF) != 0x7FFC) {
              ^
  57.         av_log(avctx, AV_LOG_ERROR + log_level_offset, "invalid sync code\n");
  58.         return AVERROR_INVALIDDATA;

libavcodec/flac.c:62:5: 
  60. 
  61.     /* variable block size stream code */
  62.     fi->is_var_size = get_bits1(gb);
          ^
  63. 
  64.     /* block size and sample rate codes */

libavcodec/get_bits.h:267:1: start of procedure get_bits1()
    265. }
    266. 
    267. static inline unsigned int get_bits1(GetBitContext *s)
         ^
    268. {
    269.     unsigned int index = s->index;

libavcodec/get_bits.h:269:5: 
    267. static inline unsigned int get_bits1(GetBitContext *s)
    268. {
    269.     unsigned int index = s->index;
             ^
    270.     uint8_t result     = s->buffer[index >> 3];
    271. #ifdef BITSTREAM_READER_LE

libavcodec/get_bits.h:270:5: 
    268. {
    269.     unsigned int index = s->index;
    270.     uint8_t result     = s->buffer[index >> 3];
             ^
    271. #ifdef BITSTREAM_READER_LE
    272.     result >>= index & 7;

libavcodec/get_bits.h:275:5: 
    273.     result  &= 1;
    274. #else
    275.     result <<= index & 7;
             ^
    276.     result >>= 8 - 1;
    277. #endif

libavcodec/get_bits.h:276:5: 
    274. #else
    275.     result <<= index & 7;
    276.     result >>= 8 - 1;
             ^
    277. #endif
    278. #if !UNCHECKED_BITSTREAM_READER

libavcodec/get_bits.h:279:9: Taking false branch
    277. #endif
    278. #if !UNCHECKED_BITSTREAM_READER
    279.     if (s->index < s->size_in_bits_plus8)
                 ^
    280. #endif
    281.         index++;

libavcodec/get_bits.h:282:5: 
    280. #endif
    281.         index++;
    282.     s->index = index;
             ^
    283. 
    284.     return result;

libavcodec/get_bits.h:284:5: 
    282.     s->index = index;
    283. 
    284.     return result;
             ^
    285. }
    286. 

libavcodec/get_bits.h:285:1: return from a call to get_bits1
    283. 
    284.     return result;
    285. }
         ^
    286. 
    287. static inline unsigned int show_bits1(GetBitContext *s)

libavcodec/flac.c:65:5: Skipping get_bits(): empty list of specs
  63. 
  64.     /* block size and sample rate codes */
  65.     bs_code = get_bits(gb, 4);
          ^
  66.     sr_code = get_bits(gb, 4);
  67. 

libavcodec/flac.c:66:5: Skipping get_bits(): empty list of specs
  64.     /* block size and sample rate codes */
  65.     bs_code = get_bits(gb, 4);
  66.     sr_code = get_bits(gb, 4);
          ^
  67. 
  68.     /* channels and decorrelation */

libavcodec/flac.c:69:5: Skipping get_bits(): empty list of specs
  67. 
  68.     /* channels and decorrelation */
  69.     fi->ch_mode = get_bits(gb, 4);
          ^
  70.     if (fi->ch_mode < FLAC_MAX_CHANNELS) {
  71.         fi->channels = fi->ch_mode + 1;

libavcodec/flac.c:70:9: Taking false branch
  68.     /* channels and decorrelation */
  69.     fi->ch_mode = get_bits(gb, 4);
  70.     if (fi->ch_mode < FLAC_MAX_CHANNELS) {
              ^
  71.         fi->channels = fi->ch_mode + 1;
  72.         fi->ch_mode = FLAC_CHMODE_INDEPENDENT;

libavcodec/flac.c:73:16: Taking true branch
  71.         fi->channels = fi->ch_mode + 1;
  72.         fi->ch_mode = FLAC_CHMODE_INDEPENDENT;
  73.     } else if (fi->ch_mode < FLAC_MAX_CHANNELS + FLAC_CHMODE_MID_SIDE) {
                     ^
  74.         fi->channels = 2;
  75.         fi->ch_mode -= FLAC_MAX_CHANNELS - 1;

libavcodec/flac.c:74:9: 
  72.         fi->ch_mode = FLAC_CHMODE_INDEPENDENT;
  73.     } else if (fi->ch_mode < FLAC_MAX_CHANNELS + FLAC_CHMODE_MID_SIDE) {
  74.         fi->channels = 2;
              ^
  75.         fi->ch_mode -= FLAC_MAX_CHANNELS - 1;
  76.     } else {

libavcodec/flac.c:75:9: 
  73.     } else if (fi->ch_mode < FLAC_MAX_CHANNELS + FLAC_CHMODE_MID_SIDE) {
  74.         fi->channels = 2;
  75.         fi->ch_mode -= FLAC_MAX_CHANNELS - 1;
              ^
  76.     } else {
  77.         av_log(avctx, AV_LOG_ERROR + log_level_offset,

libavcodec/flac.c:83:5: Skipping get_bits(): empty list of specs
  81. 
  82.     /* bits per sample */
  83.     bps_code = get_bits(gb, 3);
          ^
  84.     if (bps_code == 3 || bps_code == 7) {
  85.         av_log(avctx, AV_LOG_ERROR + log_level_offset,

libavcodec/flac.c:84:9: Taking false branch
  82.     /* bits per sample */
  83.     bps_code = get_bits(gb, 3);
  84.     if (bps_code == 3 || bps_code == 7) {
              ^
  85.         av_log(avctx, AV_LOG_ERROR + log_level_offset,
  86.                "invalid sample size code (%d)\n",

libavcodec/flac.c:84:26: Taking false branch
  82.     /* bits per sample */
  83.     bps_code = get_bits(gb, 3);
  84.     if (bps_code == 3 || bps_code == 7) {
                               ^
  85.         av_log(avctx, AV_LOG_ERROR + log_level_offset,
  86.                "invalid sample size code (%d)\n",

libavcodec/flac.c:90:5: 
  88.         return AVERROR_INVALIDDATA;
  89.     }
  90.     fi->bps = sample_size_table[bps_code];
          ^
  91. 
  92.     /* reserved bit */

libavcodec/flac.c:93:9: 
  91. 
  92.     /* reserved bit */
  93.     if (get_bits1(gb)) {
              ^
  94.         av_log(avctx, AV_LOG_ERROR + log_level_offset,
  95.                "broken stream, invalid padding\n");

libavcodec/get_bits.h:267:1: start of procedure get_bits1()
    265. }
    266. 
    267. static inline unsigned int get_bits1(GetBitContext *s)
         ^
    268. {
    269.     unsigned int index = s->index;

libavcodec/get_bits.h:269:5: 
    267. static inline unsigned int get_bits1(GetBitContext *s)
    268. {
    269.     unsigned int index = s->index;
             ^
    270.     uint8_t result     = s->buffer[index >> 3];
    271. #ifdef BITSTREAM_READER_LE

libavcodec/get_bits.h:270:5: 
    268. {
    269.     unsigned int index = s->index;
    270.     uint8_t result     = s->buffer[index >> 3];
             ^
    271. #ifdef BITSTREAM_READER_LE
    272.     result >>= index & 7;

static int frame_header_is_valid(AVCodecContext *avctx, const uint8_t *buf,
                                 FLACFrameInfo *fi)
{
    GetBitContext gb;
    init_get_bits(&gb, buf, MAX_FRAME_HEADER_SIZE * 8);
    return !ff_flac_decode_frame_header(avctx, &gb, fi, 127);
}
['static int frame_header_is_valid(AVCodecContext *avctx, const uint8_t *buf,\n                                 FLACFrameInfo *fi)\n{\n    GetBitContext gb;\n    init_get_bits(&gb, buf, MAX_FRAME_HEADER_SIZE * 8);\n    return !ff_flac_decode_frame_header(avctx, &gb, fi, 127);\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n                                int bit_size)\n{\n    int buffer_size;\n    int ret = 0;\n    if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n        bit_size    = 0;\n        buffer      = NULL;\n        ret         = AVERROR_INVALIDDATA;\n    }\n    buffer_size = (bit_size + 7) >> 3;\n    s->buffer             = buffer;\n    s->size_in_bits       = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n    s->size_in_bits_plus8 = bit_size + 8;\n#endif\n    s->buffer_end         = buffer + buffer_size;\n    s->index              = 0;\n    return ret;\n}', 'int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,\n                                FLACFrameInfo *fi, int log_level_offset)\n{\n    int bs_code, sr_code, bps_code;\n    if ((get_bits(gb, 15) & 0x7FFF) != 0x7FFC) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset, "invalid sync code\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    fi->is_var_size = get_bits1(gb);\n    bs_code = get_bits(gb, 4);\n    sr_code = get_bits(gb, 4);\n    fi->ch_mode = get_bits(gb, 4);\n    if (fi->ch_mode < FLAC_MAX_CHANNELS) {\n        fi->channels = fi->ch_mode + 1;\n        fi->ch_mode = FLAC_CHMODE_INDEPENDENT;\n    } else if (fi->ch_mode < FLAC_MAX_CHANNELS + FLAC_CHMODE_MID_SIDE) {\n        fi->channels = 2;\n        fi->ch_mode -= FLAC_MAX_CHANNELS - 1;\n    } else {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "invalid channel mode: %d\\n", fi->ch_mode);\n        return AVERROR_INVALIDDATA;\n    }\n    bps_code = get_bits(gb, 3);\n    if (bps_code == 3 || bps_code == 7) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "invalid sample size code (%d)\\n",\n               bps_code);\n        return AVERROR_INVALIDDATA;\n    }\n    fi->bps = sample_size_table[bps_code];\n    if (get_bits1(gb)) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "broken stream, invalid padding\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    fi->frame_or_sample_num = get_utf8(gb);\n    if (fi->frame_or_sample_num < 0) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "sample/frame number invalid; utf8 fscked\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    if (bs_code == 0) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "reserved blocksize code: 0\\n");\n        return AVERROR_INVALIDDATA;\n    } else if (bs_code == 6) {\n        fi->blocksize = get_bits(gb, 8) + 1;\n    } else if (bs_code == 7) {\n        fi->blocksize = get_bits(gb, 16) + 1;\n    } else {\n        fi->blocksize = ff_flac_blocksize_table[bs_code];\n    }\n    if (sr_code < 12) {\n        fi->samplerate = ff_flac_sample_rate_table[sr_code];\n    } else if (sr_code == 12) {\n        fi->samplerate = get_bits(gb, 8) * 1000;\n    } else if (sr_code == 13) {\n        fi->samplerate = get_bits(gb, 16);\n    } else if (sr_code == 14) {\n        fi->samplerate = get_bits(gb, 16) * 10;\n    } else {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "illegal sample rate code %d\\n",\n               sr_code);\n        return AVERROR_INVALIDDATA;\n    }\n    skip_bits(gb, 8);\n    if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, gb->buffer,\n               get_bits_count(gb)/8)) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "header crc mismatch\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    return 0;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n    unsigned int index = s->index;\n    uint8_t result     = s->buffer[index >> 3];\n#ifdef BITSTREAM_READER_LE\n    result >>= index & 7;\n    result  &= 1;\n#else\n    result <<= index & 7;\n    result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n    if (s->index < s->size_in_bits_plus8)\n#endif\n        index++;\n    s->index = index;\n    return result;\n}']