libavcodec/jpeg2000dec.c:1428: error: Buffer Overrun L2
  Offset: [0, -1+max(4, `avctx->priv_data->ncomponents`)] Size: 3 by call to `jpeg2000_read_bitstream_packets`.

libavcodec/jpeg2000dec.c:1380:1: Parameter `avctx->priv_data->ncomponents`
1378. }
1379. 
1380. static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
      ^
1381.                                  int *got_frame, AVPacket *avpkt)
1382. {

libavcodec/jpeg2000dec.c:1417:15: Call
1415.         goto end;
1416.     }
1417.     if (ret = jpeg2000_read_main_headers(s))
                    ^
1418.         goto end;
1419. 

libavcodec/jpeg2000dec.c:1228:1: Parameter `s->ncomponents`
  1226. }
  1227. 
  1228. static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s)
        ^
  1229. {
  1230.     Jpeg2000CodingStyle *codsty = s->codsty;

libavcodec/jpeg2000dec.c:1428:15: Call
1426.     picture->key_frame = 1;
1427. 
1428.     if (ret = jpeg2000_read_bitstream_packets(s))
                    ^
1429.         goto end;
1430.     for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++)

libavcodec/jpeg2000dec.c:1327:1: Parameter `s->ncomponents`
  1325. 
  1326. /* Read bit stream packets --> T2 operation. */
  1327. static int jpeg2000_read_bitstream_packets(Jpeg2000DecoderContext *s)
        ^
  1328. {
  1329.     int ret = 0;

libavcodec/jpeg2000dec.c:1335:19: Call
  1333.         Jpeg2000Tile *tile = s->tile + tileno;
  1334. 
  1335.         if (ret = init_tile(s, tileno))
                          ^
  1336.             return ret;
  1337. 

libavcodec/jpeg2000dec.c:572:1: Parameter `s->ncomponents`
    570. }
    571. 
    572. static int init_tile(Jpeg2000DecoderContext *s, int tileno)
         ^
    573. {
    574.     int compno;

libavcodec/jpeg2000dec.c:1339:19: Call
  1337. 
  1338.         s->g = tile->tile_part[0].tpg;
  1339.         if (ret = jpeg2000_decode_packets(s, tile))
                          ^
  1340.             return ret;
  1341.     }

libavcodec/jpeg2000dec.c:820:1: Parameter `s->ncomponents`
    818. }
    819. 
    820. static int jpeg2000_decode_packets(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
         ^
    821. {
    822.     int ret = 0;

libavcodec/jpeg2000dec.c:831:15: Call
    829. 
    830.     case JPEG2000_PGOD_CPRL:
    831.         ret = decode_pgod_cprl(s, tile);
                       ^
    832.         break;
    833. 

libavcodec/jpeg2000dec.c:766:1: <Offset trace>
764. }
765. 
766. static int decode_pgod_cprl(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
     ^
767. {
768.     int layno, reslevelno, compno, precno;

libavcodec/jpeg2000dec.c:766:1: Parameter `s->ncomponents`
      764. }
      765. 
      766. static int decode_pgod_cprl(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
           ^
      767. {
      768.     int layno, reslevelno, compno, precno;

libavcodec/jpeg2000dec.c:766:1: <Length trace>
764. }
765. 
766. static int decode_pgod_cprl(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
     ^
767. {
768.     int layno, reslevelno, compno, precno;

libavcodec/jpeg2000dec.c:766:1: Parameter `tile->tile_part[*]`
      764. }
      765. 
      766. static int decode_pgod_cprl(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
           ^
      767. {
      768.     int layno, reslevelno, compno, precno;

libavcodec/jpeg2000dec.c:778:16: Array access: Offset: [0, -1+max(4, avctx->priv_data->ncomponents)] Size: 3 by call to `jpeg2000_read_bitstream_packets` 
      776.          * For DCinema one tile-part per component, so can be
      777.          * indexed by component. */
      778.         s->g = tile->tile_part[compno].tpg;
                          ^
      779. 
      780.         /* Position loop (y axis)

static int decode_pgod_cprl(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
{
    int layno, reslevelno, compno, precno;
    int ret, x, y;
    for (compno = 0; compno < s->ncomponents; compno++) {
        Jpeg2000CodingStyle *codsty = tile->codsty + compno;
        Jpeg2000QuantStyle *qntsty  = tile->qntsty + compno;
        s->g = tile->tile_part[compno].tpg;
        for (y = 0; y < s->height; y += 256) {
            for (x = 0; x < s->width; x += 256) {
                for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
                    uint16_t prcx, prcy;
                    uint8_t reducedresno = codsty->nreslevels - 1 -reslevelno;
                    Jpeg2000ResLevel *rlevel = tile->comp[compno].reslevel + reslevelno;
                    if (!((y % (1 << (rlevel->log2_prec_height + reducedresno)) == 0) ||
                          (y == 0)))
                        continue;
                    if (!((x % (1 << (rlevel->log2_prec_width + reducedresno)) == 0) ||
                          (x == 0)))
                        continue;
                    prcx   = ff_jpeg2000_ceildivpow2(x, reducedresno) >> rlevel->log2_prec_width;
                    prcy   = ff_jpeg2000_ceildivpow2(y, reducedresno) >> rlevel->log2_prec_height;
                    precno = prcx + rlevel->num_precincts_x * prcy;
                    for (layno = 0; layno < tile->codsty[0].nlayers; layno++) {
                        if ((ret = jpeg2000_decode_packet(s, codsty, rlevel,
                                                          precno, layno,
                                                          qntsty->expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
                                                          qntsty->nguardbits)) < 0)
                            return ret;
                    }
                }
            }
        }
    }
    return 0;
}
['static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,\n                                 int *got_frame, AVPacket *avpkt)\n{\n    Jpeg2000DecoderContext *s = avctx->priv_data;\n    ThreadFrame frame = { .f = data };\n    AVFrame *picture = data;\n    int tileno, ret;\n    s->avctx     = avctx;\n    bytestream2_init(&s->g, avpkt->data, avpkt->size);\n    s->curtileno = 0;\n    if (bytestream2_get_bytes_left(&s->g) < 2) {\n        ret = AVERROR_INVALIDDATA;\n        goto end;\n    }\n    if (bytestream2_get_bytes_left(&s->g) >= 12 &&\n       (bytestream2_get_be32u(&s->g) == 12) &&\n       (bytestream2_get_be32u(&s->g) == JP2_SIG_TYPE) &&\n       (bytestream2_get_be32u(&s->g) == JP2_SIG_VALUE)) {\n        if (!jp2_find_codestream(s)) {\n            av_log(avctx, AV_LOG_ERROR,\n                   "Could not find Jpeg2000 codestream atom.\\n");\n            ret = AVERROR_INVALIDDATA;\n            goto end;\n        }\n    } else {\n        bytestream2_seek(&s->g, 0, SEEK_SET);\n    }\n    if (bytestream2_get_be16u(&s->g) != JPEG2000_SOC) {\n        av_log(avctx, AV_LOG_ERROR, "SOC marker not present\\n");\n        ret = AVERROR_INVALIDDATA;\n        goto end;\n    }\n    if (ret = jpeg2000_read_main_headers(s))\n        goto end;\n    if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0) {\n        av_log(avctx, AV_LOG_ERROR, "ff_thread_get_buffer() failed.\\n");\n        goto end;\n    }\n    picture->pict_type = AV_PICTURE_TYPE_I;\n    picture->key_frame = 1;\n    if (ret = jpeg2000_read_bitstream_packets(s))\n        goto end;\n    for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++)\n        if (ret = jpeg2000_decode_tile(s, s->tile + tileno, picture))\n            goto end;\n    jpeg2000_dec_cleanup(s);\n    *got_frame = 1;\n    return bytestream2_tell(&s->g);\nend:\n    jpeg2000_dec_cleanup(s);\n    return ret;\n}', 'static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s)\n{\n    Jpeg2000CodingStyle *codsty = s->codsty;\n    Jpeg2000QuantStyle *qntsty  = s->qntsty;\n    uint8_t *properties         = s->properties;\n    for (;;) {\n        int len, ret = 0;\n        uint16_t marker;\n        int oldpos;\n        if (bytestream2_get_bytes_left(&s->g) < 2) {\n            av_log(s->avctx, AV_LOG_ERROR, "Missing EOC\\n");\n            break;\n        }\n        marker = bytestream2_get_be16u(&s->g);\n        oldpos = bytestream2_tell(&s->g);\n        if (marker == JPEG2000_SOD) {\n            Jpeg2000Tile *tile;\n            Jpeg2000TilePart *tp;\n            if (s->curtileno < 0) {\n                av_log(s->avctx, AV_LOG_ERROR, "Missing SOT\\n");\n                return AVERROR_INVALIDDATA;\n            }\n            if (!s->tile) {\n                av_log(s->avctx, AV_LOG_ERROR, "Missing SIZ\\n");\n                return AVERROR_INVALIDDATA;\n            }\n            tile = s->tile + s->curtileno;\n            tp = tile->tile_part + tile->tp_idx;\n            bytestream2_init(&tp->tpg, s->g.buffer, tp->tp_end - s->g.buffer);\n            bytestream2_skip(&s->g, tp->tp_end - s->g.buffer);\n            continue;\n        }\n        if (marker == JPEG2000_EOC)\n            break;\n        len = bytestream2_get_be16u(&s->g);\n        if (len < 2 || bytestream2_get_bytes_left(&s->g) < len - 2)\n            return AVERROR_INVALIDDATA;\n        switch (marker) {\n        case JPEG2000_SIZ:\n            ret = get_siz(s);\n            break;\n        case JPEG2000_COC:\n            ret = get_coc(s, codsty, properties);\n            break;\n        case JPEG2000_COD:\n            ret = get_cod(s, codsty, properties);\n            break;\n        case JPEG2000_QCC:\n            ret = get_qcc(s, len, qntsty, properties);\n            break;\n        case JPEG2000_QCD:\n            ret = get_qcd(s, len, qntsty, properties);\n            break;\n        case JPEG2000_SOT:\n            if (!(ret = get_sot(s, len))) {\n                codsty = s->tile[s->curtileno].codsty;\n                qntsty = s->tile[s->curtileno].qntsty;\n                properties = s->tile[s->curtileno].properties;\n            }\n            break;\n        case JPEG2000_PLT:\n        case JPEG2000_PLM:\n        case JPEG2000_COM:\n            bytestream2_skip(&s->g, len - 2);\n            break;\n        case JPEG2000_TLM:\n            ret = get_tlm(s, len);\n            break;\n        default:\n            av_log(s->avctx, AV_LOG_ERROR,\n                   "unsupported marker 0x%.4"PRIX16" at pos 0x%X\\n",\n                   marker, bytestream2_tell(&s->g) - 4);\n            bytestream2_skip(&s->g, len - 2);\n            break;\n        }\n        if (bytestream2_tell(&s->g) - oldpos != len || ret) {\n            av_log(s->avctx, AV_LOG_ERROR,\n                   "error during processing marker segment %.4"PRIx16"\\n",\n                   marker);\n            return ret ? ret : -1;\n        }\n    }\n    return 0;\n}', 'static int jpeg2000_read_bitstream_packets(Jpeg2000DecoderContext *s)\n{\n    int ret = 0;\n    int tileno;\n    for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++) {\n        Jpeg2000Tile *tile = s->tile + tileno;\n        if (ret = init_tile(s, tileno))\n            return ret;\n        s->g = tile->tile_part[0].tpg;\n        if (ret = jpeg2000_decode_packets(s, tile))\n            return ret;\n    }\n    return 0;\n}', 'static int init_tile(Jpeg2000DecoderContext *s, int tileno)\n{\n    int compno;\n    int tilex = tileno % s->numXtiles;\n    int tiley = tileno / s->numXtiles;\n    Jpeg2000Tile *tile = s->tile + tileno;\n    if (!tile->comp)\n        return AVERROR(ENOMEM);\n    for (compno = 0; compno < s->ncomponents; compno++) {\n        Jpeg2000Component *comp = tile->comp + compno;\n        Jpeg2000CodingStyle *codsty = tile->codsty + compno;\n        Jpeg2000QuantStyle  *qntsty = tile->qntsty + compno;\n        int ret;\n        comp->coord_o[0][0] = FFMAX(tilex       * s->tile_width  + s->tile_offset_x, s->image_offset_x);\n        comp->coord_o[0][1] = FFMIN((tilex + 1) * s->tile_width  + s->tile_offset_x, s->width);\n        comp->coord_o[1][0] = FFMAX(tiley       * s->tile_height + s->tile_offset_y, s->image_offset_y);\n        comp->coord_o[1][1] = FFMIN((tiley + 1) * s->tile_height + s->tile_offset_y, s->height);\n        comp->coord[0][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], s->reduction_factor);\n        comp->coord[0][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][1], s->reduction_factor);\n        comp->coord[1][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], s->reduction_factor);\n        comp->coord[1][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[1][1], s->reduction_factor);\n        if (ret = ff_jpeg2000_init_component(comp, codsty, qntsty,\n                                             s->cbps[compno], s->cdx[compno],\n                                             s->cdy[compno], s->avctx))\n            return ret;\n    }\n    return 0;\n}', 'static int jpeg2000_decode_packets(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)\n{\n    int ret = 0;\n    s->bit_index = 8;\n    switch (tile->codsty[0].prog_order) {\n    case JPEG2000_PGOD_LRCP:\n        ret = decode_pgod_lrcp(s, tile);\n        break;\n    case JPEG2000_PGOD_CPRL:\n        ret = decode_pgod_cprl(s, tile);\n        break;\n    case JPEG2000_PGOD_RLCP:\n        avpriv_request_sample(s->avctx, "Progression order RLCP");\n        ret = AVERROR_PATCHWELCOME;\n        break;\n    case JPEG2000_PGOD_RPCL:\n        avpriv_request_sample(s->avctx, "Progression order RPCL");\n        ret = AVERROR_PATCHWELCOME;\n        break;\n    case JPEG2000_PGOD_PCRL:\n        avpriv_request_sample(s->avctx, "Progression order PCRL");\n        ret = AVERROR_PATCHWELCOME;\n        break;\n    default:\n        break;\n    }\n    bytestream2_skip(&s->g, 2);\n    return ret;\n}', 'static int decode_pgod_cprl(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)\n{\n    int layno, reslevelno, compno, precno;\n    int ret, x, y;\n    for (compno = 0; compno < s->ncomponents; compno++) {\n        Jpeg2000CodingStyle *codsty = tile->codsty + compno;\n        Jpeg2000QuantStyle *qntsty  = tile->qntsty + compno;\n        s->g = tile->tile_part[compno].tpg;\n        for (y = 0; y < s->height; y += 256) {\n            for (x = 0; x < s->width; x += 256) {\n                for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {\n                    uint16_t prcx, prcy;\n                    uint8_t reducedresno = codsty->nreslevels - 1 -reslevelno;\n                    Jpeg2000ResLevel *rlevel = tile->comp[compno].reslevel + reslevelno;\n                    if (!((y % (1 << (rlevel->log2_prec_height + reducedresno)) == 0) ||\n                          (y == 0)))\n                        continue;\n                    if (!((x % (1 << (rlevel->log2_prec_width + reducedresno)) == 0) ||\n                          (x == 0)))\n                        continue;\n                    prcx   = ff_jpeg2000_ceildivpow2(x, reducedresno) >> rlevel->log2_prec_width;\n                    prcy   = ff_jpeg2000_ceildivpow2(y, reducedresno) >> rlevel->log2_prec_height;\n                    precno = prcx + rlevel->num_precincts_x * prcy;\n                    for (layno = 0; layno < tile->codsty[0].nlayers; layno++) {\n                        if ((ret = jpeg2000_decode_packet(s, codsty, rlevel,\n                                                          precno, layno,\n                                                          qntsty->expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),\n                                                          qntsty->nguardbits)) < 0)\n                            return ret;\n                    }\n                }\n            }\n        }\n    }\n    return 0;\n}']