libavcodec/jpeg2000dec.c:1263: error: Integer Overflow L1
  ([-oo, 0] - 4):unsigned32 by call to `get_sot`.

libavcodec/jpeg2000dec.c:1220:1: Parameter `*s->g.buffer`
1218. }
1219. 
1220. static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s)
      ^
1221. {
1222.     Jpeg2000CodingStyle *codsty = s->codsty;

libavcodec/jpeg2000dec.c:1263:19: Call
1261.             break;
1262.         case JPEG2000_SOT:
1263.             ret = get_sot(s, len);
                        ^
1264.             break;
1265.         case JPEG2000_COM:

libavcodec/jpeg2000dec.c:464:1: <LHS trace>
462. 
463. /* Get start of tile segment. */
464. static int get_sot(Jpeg2000DecoderContext *s, int n)
     ^
465. {
466.     Jpeg2000TilePart *tp;

libavcodec/jpeg2000dec.c:464:1: Parameter `n`
  462. 
  463. /* Get start of tile segment. */
  464. static int get_sot(Jpeg2000DecoderContext *s, int n)
       ^
  465. {
  466.     Jpeg2000TilePart *tp;

libavcodec/jpeg2000dec.c:506:9: Binary operation: ([-oo, 0] - 4):unsigned32 by call to `get_sot` 
  504.      * Check SOD marker is present. */
  505.     if (JPEG2000_SOD == bytestream2_get_be16(&s->g)) {
  506.         bytestream2_init(&tp->tpg, s->g.buffer, tp->tp_len - n - 4);
               ^
  507.         bytestream2_skip(&s->g, tp->tp_len - n - 4);
  508.     } else {

static int get_sot(Jpeg2000DecoderContext *s, int n)
{
    Jpeg2000TilePart *tp;
    uint16_t Isot;
    uint32_t Psot;
    uint8_t TPsot;
    if (bytestream2_get_bytes_left(&s->g) < 8)
        return AVERROR_INVALIDDATA;
    Isot = bytestream2_get_be16u(&s->g);
    if (Isot >= s->numXtiles * s->numYtiles)
        return AVERROR_INVALIDDATA;
    if (Isot) {
        avpriv_request_sample(s->avctx, "Support for more than one tile");
        return AVERROR_PATCHWELCOME;
    }
    Psot  = bytestream2_get_be32u(&s->g);
    TPsot = bytestream2_get_byteu(&s->g);
    bytestream2_get_byteu(&s->g);
    if (Psot > bytestream2_get_bytes_left(&s->g) + n + 2) {
        av_log(s->avctx, AV_LOG_ERROR, "Psot %d too big\n", Psot);
        return AVERROR_INVALIDDATA;
    }
    if (TPsot >= FF_ARRAY_ELEMS(s->tile[Isot].tile_part)) {
        avpriv_request_sample(s->avctx, "Support for %d components", TPsot);
        return AVERROR_PATCHWELCOME;
    }
    tp             = s->tile[s->curtileno].tile_part + TPsot;
    tp->tile_index = Isot;
    tp->tp_len     = Psot;
    tp->tp_idx     = TPsot;
    if (JPEG2000_SOD == bytestream2_get_be16(&s->g)) {
        bytestream2_init(&tp->tpg, s->g.buffer, tp->tp_len - n - 4);
        bytestream2_skip(&s->g, tp->tp_len - n - 4);
    } else {
        av_log(s->avctx, AV_LOG_ERROR, "SOD marker not found \n");
        return AVERROR_INVALIDDATA;
    }
    return 0;
}
['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_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            ret = get_sot(s, len);\n            break;\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%.4X 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) && (marker != JPEG2000_SOT)) || ret) {\n            av_log(s->avctx, AV_LOG_ERROR,\n                   "error during processing marker segment %.4x\\n", marker);\n            return ret ? ret : -1;\n        }\n    }\n    return 0;\n}', 'static int get_sot(Jpeg2000DecoderContext *s, int n)\n{\n    Jpeg2000TilePart *tp;\n    uint16_t Isot;\n    uint32_t Psot;\n    uint8_t TPsot;\n    if (bytestream2_get_bytes_left(&s->g) < 8)\n        return AVERROR_INVALIDDATA;\n    Isot = bytestream2_get_be16u(&s->g);\n    if (Isot >= s->numXtiles * s->numYtiles)\n        return AVERROR_INVALIDDATA;\n    if (Isot) {\n        avpriv_request_sample(s->avctx, "Support for more than one tile");\n        return AVERROR_PATCHWELCOME;\n    }\n    Psot  = bytestream2_get_be32u(&s->g);\n    TPsot = bytestream2_get_byteu(&s->g);\n    bytestream2_get_byteu(&s->g);\n    if (Psot > bytestream2_get_bytes_left(&s->g) + n + 2) {\n        av_log(s->avctx, AV_LOG_ERROR, "Psot %d too big\\n", Psot);\n        return AVERROR_INVALIDDATA;\n    }\n    if (TPsot >= FF_ARRAY_ELEMS(s->tile[Isot].tile_part)) {\n        avpriv_request_sample(s->avctx, "Support for %d components", TPsot);\n        return AVERROR_PATCHWELCOME;\n    }\n    tp             = s->tile[s->curtileno].tile_part + TPsot;\n    tp->tile_index = Isot;\n    tp->tp_len     = Psot;\n    tp->tp_idx     = TPsot;\n    if (JPEG2000_SOD == bytestream2_get_be16(&s->g)) {\n        bytestream2_init(&tp->tpg, s->g.buffer, tp->tp_len - n - 4);\n        bytestream2_skip(&s->g, tp->tp_len - n - 4);\n    } else {\n        av_log(s->avctx, AV_LOG_ERROR, "SOD marker not found \\n");\n        return AVERROR_INVALIDDATA;\n    }\n    return 0;\n}']