libavformat/oggparsespeex.c:82: error: Null Dereference
  pointer `st->codecpar->extradata` last assigned on line 80 could be null and is dereferenced by call to `memcpy()` at line 82, column 9.

libavformat/oggparsespeex.c:43:1: start of procedure speex_header()
41. };
42. 
43. static int speex_header(AVFormatContext *s, int idx) {
    ^
44.     struct ogg *ogg = s->priv_data;
45.     struct ogg_stream *os = ogg->streams + idx;

libavformat/oggparsespeex.c:44:5: 
42. 
43. static int speex_header(AVFormatContext *s, int idx) {
44.     struct ogg *ogg = s->priv_data;
        ^
45.     struct ogg_stream *os = ogg->streams + idx;
46.     struct speex_params *spxp = os->private;

libavformat/oggparsespeex.c:45:5: 
43. static int speex_header(AVFormatContext *s, int idx) {
44.     struct ogg *ogg = s->priv_data;
45.     struct ogg_stream *os = ogg->streams + idx;
        ^
46.     struct speex_params *spxp = os->private;
47.     AVStream *st = s->streams[idx];

libavformat/oggparsespeex.c:46:5: 
44.     struct ogg *ogg = s->priv_data;
45.     struct ogg_stream *os = ogg->streams + idx;
46.     struct speex_params *spxp = os->private;
        ^
47.     AVStream *st = s->streams[idx];
48.     uint8_t *p = os->buf + os->pstart;

libavformat/oggparsespeex.c:47:5: 
45.     struct ogg_stream *os = ogg->streams + idx;
46.     struct speex_params *spxp = os->private;
47.     AVStream *st = s->streams[idx];
        ^
48.     uint8_t *p = os->buf + os->pstart;
49. 

libavformat/oggparsespeex.c:48:5: 
46.     struct speex_params *spxp = os->private;
47.     AVStream *st = s->streams[idx];
48.     uint8_t *p = os->buf + os->pstart;
        ^
49. 
50.     if (!spxp) {

libavformat/oggparsespeex.c:50:10: Taking false branch
48.     uint8_t *p = os->buf + os->pstart;
49. 
50.     if (!spxp) {
             ^
51.         spxp = av_mallocz(sizeof(*spxp));
52.         if (!spxp)

libavformat/oggparsespeex.c:57:9: Taking false branch
55.     }
56. 
57.     if (spxp->seq > 1)
            ^
58.         return 0;
59. 

libavformat/oggparsespeex.c:60:9: Taking true branch
58.         return 0;
59. 
60.     if (spxp->seq == 0) {
            ^
61.         int frames_per_packet;
62.         st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;

libavformat/oggparsespeex.c:62:9: 
60.     if (spxp->seq == 0) {
61.         int frames_per_packet;
62.         st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
            ^
63.         st->codecpar->codec_id = AV_CODEC_ID_SPEEX;
64. 

libavformat/oggparsespeex.c:63:9: 
61.         int frames_per_packet;
62.         st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
63.         st->codecpar->codec_id = AV_CODEC_ID_SPEEX;
            ^
64. 
65.         st->codecpar->sample_rate = AV_RL32(p + 36);

libavformat/oggparsespeex.c:65:9: 
63.         st->codecpar->codec_id = AV_CODEC_ID_SPEEX;
64. 
65.         st->codecpar->sample_rate = AV_RL32(p + 36);
            ^
66.         st->codecpar->channels = AV_RL32(p + 48);
67.         if (st->codecpar->channels < 1 || st->codecpar->channels > 2) {

libavformat/oggparsespeex.c:66:9: 
64. 
65.         st->codecpar->sample_rate = AV_RL32(p + 36);
66.         st->codecpar->channels = AV_RL32(p + 48);
            ^
67.         if (st->codecpar->channels < 1 || st->codecpar->channels > 2) {
68.             av_log(s, AV_LOG_ERROR, "invalid channel count. Speex must be mono or stereo.\n");

libavformat/oggparsespeex.c:67:13: Taking false branch
65.         st->codecpar->sample_rate = AV_RL32(p + 36);
66.         st->codecpar->channels = AV_RL32(p + 48);
67.         if (st->codecpar->channels < 1 || st->codecpar->channels > 2) {
                ^
68.             av_log(s, AV_LOG_ERROR, "invalid channel count. Speex must be mono or stereo.\n");
69.             return AVERROR_INVALIDDATA;

libavformat/oggparsespeex.c:67:43: Taking false branch
65.         st->codecpar->sample_rate = AV_RL32(p + 36);
66.         st->codecpar->channels = AV_RL32(p + 48);
67.         if (st->codecpar->channels < 1 || st->codecpar->channels > 2) {
                                              ^
68.             av_log(s, AV_LOG_ERROR, "invalid channel count. Speex must be mono or stereo.\n");
69.             return AVERROR_INVALIDDATA;

libavformat/oggparsespeex.c:71:40: Condition is false
69.             return AVERROR_INVALIDDATA;
70.         }
71.         st->codecpar->channel_layout = st->codecpar->channels == 1 ? AV_CH_LAYOUT_MONO :
                                           ^
72.                                                                      AV_CH_LAYOUT_STEREO;
73. 

libavformat/oggparsespeex.c:71:9: 
69.             return AVERROR_INVALIDDATA;
70.         }
71.         st->codecpar->channel_layout = st->codecpar->channels == 1 ? AV_CH_LAYOUT_MONO :
            ^
72.                                                                      AV_CH_LAYOUT_STEREO;
73. 

libavformat/oggparsespeex.c:74:9: 
72.                                                                      AV_CH_LAYOUT_STEREO;
73. 
74.         spxp->packet_size  = AV_RL32(p + 56);
            ^
75.         frames_per_packet  = AV_RL32(p + 64);
76.         if (frames_per_packet)

libavformat/oggparsespeex.c:75:9: 
73. 
74.         spxp->packet_size  = AV_RL32(p + 56);
75.         frames_per_packet  = AV_RL32(p + 64);
            ^
76.         if (frames_per_packet)
77.             spxp->packet_size *= frames_per_packet;

libavformat/oggparsespeex.c:76:13: Taking true branch
74.         spxp->packet_size  = AV_RL32(p + 56);
75.         frames_per_packet  = AV_RL32(p + 64);
76.         if (frames_per_packet)
                ^
77.             spxp->packet_size *= frames_per_packet;
78. 

libavformat/oggparsespeex.c:77:13: 
75.         frames_per_packet  = AV_RL32(p + 64);
76.         if (frames_per_packet)
77.             spxp->packet_size *= frames_per_packet;
                ^
78. 
79.         st->codecpar->extradata_size = os->psize;

libavformat/oggparsespeex.c:79:9: 
77.             spxp->packet_size *= frames_per_packet;
78. 
79.         st->codecpar->extradata_size = os->psize;
            ^
80.         st->codecpar->extradata = av_malloc(st->codecpar->extradata_size
81.                                             + AV_INPUT_BUFFER_PADDING_SIZE);

libavformat/oggparsespeex.c:80:9: 
78. 
79.         st->codecpar->extradata_size = os->psize;
80.         st->codecpar->extradata = av_malloc(st->codecpar->extradata_size
            ^
81.                                             + AV_INPUT_BUFFER_PADDING_SIZE);
82.         memcpy(st->codecpar->extradata, p, st->codecpar->extradata_size);

libavutil/mem.c:62:1: start of procedure av_malloc()
  60.  * linker will do it automatically. */
  61. 
  62. void *av_malloc(size_t size)
      ^
  63. {
  64.     void *ptr = NULL;

libavutil/mem.c:64:5: 
  62. void *av_malloc(size_t size)
  63. {
  64.     void *ptr = NULL;
          ^
  65. #if CONFIG_MEMALIGN_HACK
  66.     long diff;

libavutil/mem.c:70:9: Taking true branch
  68. 
  69.     /* let's disallow possibly ambiguous cases */
  70.     if (size > (INT_MAX - 32) || !size)
              ^
  71.         return NULL;
  72. 

libavutil/mem.c:71:9: 
  69.     /* let's disallow possibly ambiguous cases */
  70.     if (size > (INT_MAX - 32) || !size)
  71.         return NULL;
              ^
  72. 
  73. #if CONFIG_MEMALIGN_HACK

libavutil/mem.c:115:1: return from a call to av_malloc
  113. #endif
  114.     return ptr;
  115. }
       ^
  116. 
  117. void *av_realloc(void *ptr, size_t size)

libavformat/oggparsespeex.c:82:9: 
80.         st->codecpar->extradata = av_malloc(st->codecpar->extradata_size
81.                                             + AV_INPUT_BUFFER_PADDING_SIZE);
82.         memcpy(st->codecpar->extradata, p, st->codecpar->extradata_size);
            ^
83. 
84.         avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);

static int speex_header(AVFormatContext *s, int idx) {
    struct ogg *ogg = s->priv_data;
    struct ogg_stream *os = ogg->streams + idx;
    struct speex_params *spxp = os->private;
    AVStream *st = s->streams[idx];
    uint8_t *p = os->buf + os->pstart;
    if (!spxp) {
        spxp = av_mallocz(sizeof(*spxp));
        if (!spxp)
            return AVERROR(ENOMEM);
        os->private = spxp;
    }
    if (spxp->seq > 1)
        return 0;
    if (spxp->seq == 0) {
        int frames_per_packet;
        st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
        st->codecpar->codec_id = AV_CODEC_ID_SPEEX;
        st->codecpar->sample_rate = AV_RL32(p + 36);
        st->codecpar->channels = AV_RL32(p + 48);
        if (st->codecpar->channels < 1 || st->codecpar->channels > 2) {
            av_log(s, AV_LOG_ERROR, "invalid channel count. Speex must be mono or stereo.\n");
            return AVERROR_INVALIDDATA;
        }
        st->codecpar->channel_layout = st->codecpar->channels == 1 ? AV_CH_LAYOUT_MONO :
                                                                     AV_CH_LAYOUT_STEREO;
        spxp->packet_size  = AV_RL32(p + 56);
        frames_per_packet  = AV_RL32(p + 64);
        if (frames_per_packet)
            spxp->packet_size *= frames_per_packet;
        st->codecpar->extradata_size = os->psize;
        st->codecpar->extradata = av_malloc(st->codecpar->extradata_size
                                            + AV_INPUT_BUFFER_PADDING_SIZE);
        memcpy(st->codecpar->extradata, p, st->codecpar->extradata_size);
        avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
    } else
        ff_vorbis_stream_comment(s, st, p, os->psize);
    spxp->seq++;
    return 1;
}
['static int speex_header(AVFormatContext *s, int idx) {\n    struct ogg *ogg = s->priv_data;\n    struct ogg_stream *os = ogg->streams + idx;\n    struct speex_params *spxp = os->private;\n    AVStream *st = s->streams[idx];\n    uint8_t *p = os->buf + os->pstart;\n    if (!spxp) {\n        spxp = av_mallocz(sizeof(*spxp));\n        if (!spxp)\n            return AVERROR(ENOMEM);\n        os->private = spxp;\n    }\n    if (spxp->seq > 1)\n        return 0;\n    if (spxp->seq == 0) {\n        int frames_per_packet;\n        st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;\n        st->codecpar->codec_id = AV_CODEC_ID_SPEEX;\n        st->codecpar->sample_rate = AV_RL32(p + 36);\n        st->codecpar->channels = AV_RL32(p + 48);\n        if (st->codecpar->channels < 1 || st->codecpar->channels > 2) {\n            av_log(s, AV_LOG_ERROR, "invalid channel count. Speex must be mono or stereo.\\n");\n            return AVERROR_INVALIDDATA;\n        }\n        st->codecpar->channel_layout = st->codecpar->channels == 1 ? AV_CH_LAYOUT_MONO :\n                                                                     AV_CH_LAYOUT_STEREO;\n        spxp->packet_size  = AV_RL32(p + 56);\n        frames_per_packet  = AV_RL32(p + 64);\n        if (frames_per_packet)\n            spxp->packet_size *= frames_per_packet;\n        st->codecpar->extradata_size = os->psize;\n        st->codecpar->extradata = av_malloc(st->codecpar->extradata_size\n                                            + AV_INPUT_BUFFER_PADDING_SIZE);\n        memcpy(st->codecpar->extradata, p, st->codecpar->extradata_size);\n        avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);\n    } else\n        ff_vorbis_stream_comment(s, st, p, os->psize);\n    spxp->seq++;\n    return 1;\n}', 'void *av_malloc(size_t size)\n{\n    void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n    long diff;\n#endif\n    if (size > (INT_MAX - 32) || !size)\n        return NULL;\n#if CONFIG_MEMALIGN_HACK\n    ptr = malloc(size + 32);\n    if (!ptr)\n        return ptr;\n    diff              = ((-(long)ptr - 1) & 31) + 1;\n    ptr               = (char *)ptr + diff;\n    ((char *)ptr)[-1] = diff;\n#elif HAVE_POSIX_MEMALIGN\n    if (posix_memalign(&ptr, 32, size))\n        ptr = NULL;\n#elif HAVE_ALIGNED_MALLOC\n    ptr = _aligned_malloc(size, 32);\n#elif HAVE_MEMALIGN\n    ptr = memalign(32, size);\n#else\n    ptr = malloc(size);\n#endif\n    return ptr;\n}']