libavformat/dv.c:468: error: Buffer Overrun L2
  Offset: [0, 7] Size: 3 by call to `avpriv_dv_produce_packet`.

libavformat/dv.c:465:13: Call
463.             return AVERROR(EIO);
464.         size = c->dv_demux->sys->frame_size;
465.         if (avio_read(s->pb, c->buf, size) <= 0)
                 ^
466.             return AVERROR(EIO);
467. 

libavformat/aviobuf.c:435:1: Parameter `*buf`
  433. }
  434. 
  435. int avio_read(AVIOContext *s, unsigned char *buf, int size)
       ^
  436. {
  437.     int len, size1;

libavformat/dv.c:468:16: Call
466.             return AVERROR(EIO);
467. 
468.         size = avpriv_dv_produce_packet(c->dv_demux, pkt, c->buf, size);
                    ^
469.     }
470. 

libavformat/dv.c:325:1: Parameter `*buf`
  323. }
  324. 
  325. int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
       ^
  326.                       uint8_t* buf, int buf_size)
  327. {

libavformat/dv.c:332:20: Call
  330. 
  331.     if (buf_size < DV_PROFILE_BYTES ||
  332.         !(c->sys = avpriv_dv_frame_profile(c->sys, buf, buf_size)) ||
                          ^
  333.         buf_size < c->sys->frame_size) {
  334.           return -1;   /* Broken frame, or not enough data */

libavcodec/dvdata.c:248:1: Parameter `*frame`
    246. };
    247. 
    248. const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys,
         ^
    249.                                   const uint8_t* frame, unsigned buf_size)
    250. {

libavformat/dv.c:346:9: Call
  344.     }
  345.     if (c->ach)
  346.         dv_extract_audio(buf, ppcm, c->sys);
               ^
  347. 
  348.     /* We work with 720p frames split in half, thus even frames have

libavformat/dv.c:105:1: <Offset trace>
103.  *    are converted into 16bit linear ones.
104.  */
105. static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4],
     ^
106.                             const DVprofile *sys)
107. {

libavformat/dv.c:105:1: Parameter `*frame`
    103.  *    are converted into 16bit linear ones.
    104.  */
    105. static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4],
         ^
    106.                             const DVprofile *sys)
    107. {

libavformat/dv.c:113:15: Call
    111.     uint8_t *pcm, ipcm;
    112. 
    113.     as_pack = dv_extract_pack(frame, dv_audio_source);
                       ^
    114.     if (!as_pack)    /* No audio ? */
    115.         return 0;

libavformat/dv.c:76:1: Parameter `t`
      74.  * to have a fallback mechanism for complete search of missing packs.
      75.  */
      76. static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t)
          ^
      77. {
      78.     int offs;

libavformat/dv.c:118:5: Assignment
    116. 
    117.     smpls =  as_pack[1] & 0x3f;       /* samples in this frame - min. samples */
    118.     freq  = (as_pack[4] >> 3) & 0x07; /* 0 - 48kHz, 1 - 44,1kHz, 2 - 32kHz */
             ^
    119.     quant =  as_pack[4] & 0x07;       /* 0 - 16bit linear, 1 - 12bit nonlinear */
    120. 

libavformat/dv.c:105:1: <Length trace>
103.  *    are converted into 16bit linear ones.
104.  */
105. static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4],
     ^
106.                             const DVprofile *sys)
107. {

libavformat/dv.c:105:1: Parameter `sys->audio_min_samples[*]`
    103.  *    are converted into 16bit linear ones.
    104.  */
    105. static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4],
         ^
    106.                             const DVprofile *sys)
    107. {

libavformat/dv.c:124:13: Array access: Offset: [0, 7] Size: 3 by call to `avpriv_dv_produce_packet` 
    122.         return -1; /* unsupported quantization */
    123. 
    124.     size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */
                     ^
    125.     half_ch = sys->difseg_size / 2;
    126. 

static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4],
                            const DVprofile *sys)
{
    int size, chan, i, j, d, of, smpls, freq, quant, half_ch;
    uint16_t lc, rc;
    const uint8_t* as_pack;
    uint8_t *pcm, ipcm;
    as_pack = dv_extract_pack(frame, dv_audio_source);
    if (!as_pack)
        return 0;
    smpls =  as_pack[1] & 0x3f;
    freq  = (as_pack[4] >> 3) & 0x07;
    quant =  as_pack[4] & 0x07;
    if (quant > 1)
        return -1;
    size = (sys->audio_min_samples[freq] + smpls) * 4;
    half_ch = sys->difseg_size / 2;
    ipcm = (sys->height == 720 && !(frame[1] & 0x0C)) ? 2 : 0;
    for (chan = 0; chan < sys->n_difchan; chan++) {
        pcm = ppcm[ipcm++];
        if (!pcm)
            break;
        for (i = 0; i < sys->difseg_size; i++) {
            frame += 6 * 80;
            if (quant == 1 && i == half_ch) {
                pcm = ppcm[ipcm++];
                if (!pcm)
                    break;
            }
            for (j = 0; j < 9; j++) {
                for (d = 8; d < 80; d += 2) {
                    if (quant == 0) {
                        of = sys->audio_shuffle[i][j] + (d - 8) / 2 * sys->audio_stride;
                        if (of*2 >= size)
                            continue;
                        pcm[of*2]   = frame[d+1];
                        pcm[of*2+1] = frame[d];
                        if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00)
                            pcm[of*2+1] = 0;
                    } else {
                        lc = ((uint16_t)frame[d]   << 4) |
                             ((uint16_t)frame[d+2] >> 4);
                        rc = ((uint16_t)frame[d+1] << 4) |
                             ((uint16_t)frame[d+2] & 0x0f);
                        lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc));
                        rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc));
                        of = sys->audio_shuffle[i%half_ch][j] + (d - 8) / 3 * sys->audio_stride;
                        if (of*2 >= size)
                            continue;
                        pcm[of*2]   = lc & 0xff;
                        pcm[of*2+1] = lc >> 8;
                        of = sys->audio_shuffle[i%half_ch+half_ch][j] +
                            (d - 8) / 3 * sys->audio_stride;
                        pcm[of*2]   = rc & 0xff;
                        pcm[of*2+1] = rc >> 8;
                        ++d;
                    }
                }
                frame += 16 * 80;
            }
        }
    }
    return size;
}
['static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)\n{\n    int size;\n    RawDVContext *c = s->priv_data;\n    size = avpriv_dv_get_packet(c->dv_demux, pkt);\n    if (size < 0) {\n        if (!c->dv_demux->sys)\n            return AVERROR(EIO);\n        size = c->dv_demux->sys->frame_size;\n        if (avio_read(s->pb, c->buf, size) <= 0)\n            return AVERROR(EIO);\n        size = avpriv_dv_produce_packet(c->dv_demux, pkt, c->buf, size);\n    }\n    return size;\n}', 'int avio_read(AVIOContext *s, unsigned char *buf, int size)\n{\n    int len, size1;\n    size1 = size;\n    while (size > 0) {\n        len = s->buf_end - s->buf_ptr;\n        if (len > size)\n            len = size;\n        if (len == 0) {\n            if(size > s->buffer_size && !s->update_checksum){\n                if(s->read_packet)\n                    len = s->read_packet(s->opaque, buf, size);\n                if (len <= 0) {\n                    s->eof_reached = 1;\n                    if(len<0)\n                        s->error= len;\n                    break;\n                } else {\n                    s->pos += len;\n                    size -= len;\n                    buf += len;\n                    s->buf_ptr = s->buffer;\n                    s->buf_end = s->buffer ;\n                }\n            }else{\n                fill_buffer(s);\n                len = s->buf_end - s->buf_ptr;\n                if (len == 0)\n                    break;\n            }\n        } else {\n            memcpy(buf, s->buf_ptr, len);\n            buf += len;\n            s->buf_ptr += len;\n            size -= len;\n        }\n    }\n    if (size1 == size) {\n        if (s->error)         return s->error;\n        if (s->eof_reached)   return AVERROR_EOF;\n    }\n    return size1 - size;\n}', 'int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,\n                      uint8_t* buf, int buf_size)\n{\n    int size, i;\n    uint8_t *ppcm[4] = {0};\n    if (buf_size < DV_PROFILE_BYTES ||\n        !(c->sys = avpriv_dv_frame_profile(c->sys, buf, buf_size)) ||\n        buf_size < c->sys->frame_size) {\n          return -1;\n    }\n    size = dv_extract_audio_info(c, buf);\n    for (i = 0; i < c->ach; i++) {\n       c->audio_pkt[i].size = size;\n       c->audio_pkt[i].pts  = c->abytes * 30000*8 / c->ast[i]->codec->bit_rate;\n       ppcm[i] = c->audio_buf[i];\n    }\n    if (c->ach)\n        dv_extract_audio(buf, ppcm, c->sys);\n    if (c->sys->height == 720) {\n        if (buf[1] & 0x0C) {\n            c->audio_pkt[2].size = c->audio_pkt[3].size = 0;\n        } else {\n            c->audio_pkt[0].size = c->audio_pkt[1].size = 0;\n            c->abytes += size;\n        }\n    } else {\n        c->abytes += size;\n    }\n    size = dv_extract_video_info(c, buf);\n    av_init_packet(pkt);\n    pkt->data         = buf;\n    pkt->size         = size;\n    pkt->flags       |= AV_PKT_FLAG_KEY;\n    pkt->stream_index = c->vst->id;\n    pkt->pts          = c->frames;\n    c->frames++;\n    return size;\n}', 'const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys,\n                                  const uint8_t* frame, unsigned buf_size)\n{\n   int i;\n   int dsf = (frame[3] & 0x80) >> 7;\n   int stype = frame[80*5 + 48 + 3] & 0x1f;\n   if (dsf == 1 && stype == 0 && frame[4] & 0x07  ) {\n       return &dv_profiles[2];\n   }\n   for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)\n       if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)\n           return &dv_profiles[i];\n   if (sys && buf_size == sys->frame_size)\n       return sys;\n   return NULL;\n}', 'static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4],\n                            const DVprofile *sys)\n{\n    int size, chan, i, j, d, of, smpls, freq, quant, half_ch;\n    uint16_t lc, rc;\n    const uint8_t* as_pack;\n    uint8_t *pcm, ipcm;\n    as_pack = dv_extract_pack(frame, dv_audio_source);\n    if (!as_pack)\n        return 0;\n    smpls =  as_pack[1] & 0x3f;\n    freq  = (as_pack[4] >> 3) & 0x07;\n    quant =  as_pack[4] & 0x07;\n    if (quant > 1)\n        return -1;\n    size = (sys->audio_min_samples[freq] + smpls) * 4;\n    half_ch = sys->difseg_size / 2;\n    ipcm = (sys->height == 720 && !(frame[1] & 0x0C)) ? 2 : 0;\n    for (chan = 0; chan < sys->n_difchan; chan++) {\n        pcm = ppcm[ipcm++];\n        if (!pcm)\n            break;\n        for (i = 0; i < sys->difseg_size; i++) {\n            frame += 6 * 80;\n            if (quant == 1 && i == half_ch) {\n                pcm = ppcm[ipcm++];\n                if (!pcm)\n                    break;\n            }\n            for (j = 0; j < 9; j++) {\n                for (d = 8; d < 80; d += 2) {\n                    if (quant == 0) {\n                        of = sys->audio_shuffle[i][j] + (d - 8) / 2 * sys->audio_stride;\n                        if (of*2 >= size)\n                            continue;\n                        pcm[of*2]   = frame[d+1];\n                        pcm[of*2+1] = frame[d];\n                        if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00)\n                            pcm[of*2+1] = 0;\n                    } else {\n                        lc = ((uint16_t)frame[d]   << 4) |\n                             ((uint16_t)frame[d+2] >> 4);\n                        rc = ((uint16_t)frame[d+1] << 4) |\n                             ((uint16_t)frame[d+2] & 0x0f);\n                        lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc));\n                        rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc));\n                        of = sys->audio_shuffle[i%half_ch][j] + (d - 8) / 3 * sys->audio_stride;\n                        if (of*2 >= size)\n                            continue;\n                        pcm[of*2]   = lc & 0xff;\n                        pcm[of*2+1] = lc >> 8;\n                        of = sys->audio_shuffle[i%half_ch+half_ch][j] +\n                            (d - 8) / 3 * sys->audio_stride;\n                        pcm[of*2]   = rc & 0xff;\n                        pcm[of*2+1] = rc >> 8;\n                        ++d;\n                    }\n                }\n                frame += 16 * 80;\n            }\n        }\n    }\n    return size;\n}', 'static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t)\n{\n    int offs;\n    switch (t) {\n    case dv_audio_source:\n        offs = (80*6 + 80*16*3 + 3);\n        break;\n    case dv_audio_control:\n        offs = (80*6 + 80*16*4 + 3);\n        break;\n    case dv_video_control:\n        offs = (80*5 + 48 + 5);\n        break;\n    default:\n        return NULL;\n    }\n    return frame[offs] == t ? &frame[offs] : NULL;\n}']