libavcodec/mlpdec.c:1003: error: Null Dereference
  pointer `&gb->buffer` last assigned on line 981 could be null and is dereferenced by call to `get_bits1()` at line 1003, column 29.

libavcodec/mlpdec.c:957:1: start of procedure read_access_unit()
955.  *  otherwise the number of bytes consumed. */
956. 
957. static int read_access_unit(AVCodecContext *avctx, void* data,
     ^
958.                             int *got_frame_ptr, AVPacket *avpkt)
959. {

libavcodec/mlpdec.c:960:5: 
958.                             int *got_frame_ptr, AVPacket *avpkt)
959. {
960.     const uint8_t *buf = avpkt->data;
         ^
961.     int buf_size = avpkt->size;
962.     MLPDecodeContext *m = avctx->priv_data;

libavcodec/mlpdec.c:961:5: 
959. {
960.     const uint8_t *buf = avpkt->data;
961.     int buf_size = avpkt->size;
         ^
962.     MLPDecodeContext *m = avctx->priv_data;
963.     GetBitContext gb;

libavcodec/mlpdec.c:962:5: 
960.     const uint8_t *buf = avpkt->data;
961.     int buf_size = avpkt->size;
962.     MLPDecodeContext *m = avctx->priv_data;
         ^
963.     GetBitContext gb;
964.     unsigned int length, substr;

libavcodec/mlpdec.c:966:5: 
964.     unsigned int length, substr;
965.     unsigned int substream_start;
966.     unsigned int header_size = 4;
         ^
967.     unsigned int substr_header_size = 0;
968.     uint8_t substream_parity_present[MAX_SUBSTREAMS];

libavcodec/mlpdec.c:967:5: 
965.     unsigned int substream_start;
966.     unsigned int header_size = 4;
967.     unsigned int substr_header_size = 0;
         ^
968.     uint8_t substream_parity_present[MAX_SUBSTREAMS];
969.     uint16_t substream_data_len[MAX_SUBSTREAMS];

libavcodec/mlpdec.c:973:9: Taking false branch
971.     int ret;
972. 
973.     if (buf_size < 4)
             ^
974.         return 0;
975. 

libavcodec/mlpdec.c:976:5: 
974.         return 0;
975. 
976.     length = (AV_RB16(buf) & 0xfff) * 2;
         ^
977. 
978.     if (length < 4 || length > buf_size)

libavutil/bswap.h:58:1: start of procedure av_bswap16()
  56. 
  57. #ifndef av_bswap16
  58. static av_always_inline av_const uint16_t av_bswap16(uint16_t x)
      ^
  59. {
  60.     x= (x>>8) | (x<<8);

libavutil/bswap.h:60:5: 
  58. static av_always_inline av_const uint16_t av_bswap16(uint16_t x)
  59. {
  60.     x= (x>>8) | (x<<8);
          ^
  61.     return x;
  62. }

libavutil/bswap.h:61:5: 
  59. {
  60.     x= (x>>8) | (x<<8);
  61.     return x;
          ^
  62. }
  63. #endif

libavutil/bswap.h:62:1: return from a call to av_bswap16
  60.     x= (x>>8) | (x<<8);
  61.     return x;
  62. }
      ^
  63. #endif
  64. 

libavcodec/mlpdec.c:978:9: Taking false branch
976.     length = (AV_RB16(buf) & 0xfff) * 2;
977. 
978.     if (length < 4 || length > buf_size)
             ^
979.         return AVERROR_INVALIDDATA;
980. 

libavcodec/mlpdec.c:978:23: Taking false branch
976.     length = (AV_RB16(buf) & 0xfff) * 2;
977. 
978.     if (length < 4 || length > buf_size)
                           ^
979.         return AVERROR_INVALIDDATA;
980. 

libavcodec/mlpdec.c:981:5: 
979.         return AVERROR_INVALIDDATA;
980. 
981.     init_get_bits(&gb, (buf + 4), (length - 4) * 8);
         ^
982. 
983.     m->is_major_sync_unit = 0;

libavcodec/get_bits.h:343:1: start of procedure init_get_bits()
  341.  * @param bit_size the size of the buffer in bits
  342.  */
  343. static inline void init_get_bits(GetBitContext *s, const uint8_t *buffer,
       ^
  344.                                  int bit_size)
  345. {

libavcodec/get_bits.h:346:5: 
  344.                                  int bit_size)
  345. {
  346.     int buffer_size = (bit_size+7)>>3;
           ^
  347.     if (buffer_size < 0 || bit_size < 0) {
  348.         buffer_size = bit_size = 0;

libavcodec/get_bits.h:347:9: Taking true branch
  345. {
  346.     int buffer_size = (bit_size+7)>>3;
  347.     if (buffer_size < 0 || bit_size < 0) {
               ^
  348.         buffer_size = bit_size = 0;
  349.         buffer = NULL;

libavcodec/get_bits.h:348:9: 
  346.     int buffer_size = (bit_size+7)>>3;
  347.     if (buffer_size < 0 || bit_size < 0) {
  348.         buffer_size = bit_size = 0;
               ^
  349.         buffer = NULL;
  350.     }

libavcodec/get_bits.h:349:9: 
  347.     if (buffer_size < 0 || bit_size < 0) {
  348.         buffer_size = bit_size = 0;
  349.         buffer = NULL;
               ^
  350.     }
  351. 

libavcodec/get_bits.h:352:5: 
  350.     }
  351. 
  352.     s->buffer       = buffer;
           ^
  353.     s->size_in_bits = bit_size;
  354. #if !UNCHECKED_BITSTREAM_READER

libavcodec/get_bits.h:353:5: 
  351. 
  352.     s->buffer       = buffer;
  353.     s->size_in_bits = bit_size;
           ^
  354. #if !UNCHECKED_BITSTREAM_READER
  355.     s->size_in_bits_plus8 = bit_size + 8;

libavcodec/get_bits.h:355:5: 
  353.     s->size_in_bits = bit_size;
  354. #if !UNCHECKED_BITSTREAM_READER
  355.     s->size_in_bits_plus8 = bit_size + 8;
           ^
  356. #endif
  357.     s->buffer_end   = buffer + buffer_size;

libavcodec/get_bits.h:357:5: 
  355.     s->size_in_bits_plus8 = bit_size + 8;
  356. #endif
  357.     s->buffer_end   = buffer + buffer_size;
           ^
  358.     s->index        = 0;
  359. }

libavcodec/get_bits.h:358:5: 
  356. #endif
  357.     s->buffer_end   = buffer + buffer_size;
  358.     s->index        = 0;
           ^
  359. }
  360. 

libavcodec/get_bits.h:359:1: return from a call to init_get_bits
  357.     s->buffer_end   = buffer + buffer_size;
  358.     s->index        = 0;
  359. }
       ^
  360. 
  361. static inline void align_get_bits(GetBitContext *s)

libavcodec/mlpdec.c:983:5: 
981.     init_get_bits(&gb, (buf + 4), (length - 4) * 8);
982. 
983.     m->is_major_sync_unit = 0;
         ^
984.     if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) {
985.         if (read_major_sync(m, &gb) < 0)

libavcodec/mlpdec.c:984:9: 
982. 
983.     m->is_major_sync_unit = 0;
984.     if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) {
             ^
985.         if (read_major_sync(m, &gb) < 0)
986.             goto error;

libavcodec/get_bits.h:318:1: start of procedure show_bits_long()
  316.  * Show 0-32 bits.
  317.  */
  318. static inline unsigned int show_bits_long(GetBitContext *s, int n)
       ^
  319. {
  320.     if (n <= MIN_CACHE_BITS)

libavcodec/get_bits.h:320:9: Taking false branch
  318. static inline unsigned int show_bits_long(GetBitContext *s, int n)
  319. {
  320.     if (n <= MIN_CACHE_BITS)
               ^
  321.         return show_bits(s, n);
  322.     else {

libavcodec/get_bits.h:323:9: 
  321.         return show_bits(s, n);
  322.     else {
  323.         GetBitContext gb = *s;
               ^
  324.         return get_bits_long(&gb, n);
  325.     }

libavcodec/get_bits.h:324:9: 
  322.     else {
  323.         GetBitContext gb = *s;
  324.         return get_bits_long(&gb, n);
               ^
  325.     }
  326. }

libavcodec/get_bits.h:292:1: start of procedure get_bits_long()
    290.  * Read 0-32 bits.
    291.  */
    292. static inline unsigned int get_bits_long(GetBitContext *s, int n)
         ^
    293. {
    294.     if (n <= MIN_CACHE_BITS)

libavcodec/get_bits.h:294:9: Taking false branch
    292. static inline unsigned int get_bits_long(GetBitContext *s, int n)
    293. {
    294.     if (n <= MIN_CACHE_BITS)
                 ^
    295.         return get_bits(s, n);
    296.     else {

libavcodec/get_bits.h:301:9: 
    299.         return ret | (get_bits(s, n-16) << 16);
    300. #else
    301.         int ret = get_bits(s, 16) << (n-16);
                 ^
    302.         return ret | get_bits(s, n-16);
    303. #endif

libavcodec/get_bits.h:228:1: start of procedure get_bits()
      226.  * Read 1-25 bits.
      227.  */
      228. static inline unsigned int get_bits(GetBitContext *s, int n)
           ^
      229. {
      230.     register int tmp;

libavcodec/get_bits.h:231:5: 
      229. {
      230.     register int tmp;
      231.     OPEN_READER(re, s);
               ^
      232.     UPDATE_CACHE(re, s);
      233.     tmp = SHOW_UBITS(re, s, n);

libavcodec/get_bits.h:232:5: 
      230.     register int tmp;
      231.     OPEN_READER(re, s);
      232.     UPDATE_CACHE(re, s);
               ^
      233.     tmp = SHOW_UBITS(re, s, n);
      234.     LAST_SKIP_BITS(re, s, n);

libavutil/bswap.h:66:1: start of procedure av_bswap32()
        64. 
        65. #ifndef av_bswap32
        66. static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
            ^
        67. {
        68.     return AV_BSWAP32C(x);

libavutil/bswap.h:68:5: 
        66. static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
        67. {
        68.     return AV_BSWAP32C(x);
                ^
        69. }
        70. #endif

libavutil/bswap.h:69:1: return from a call to av_bswap32
        67. {
        68.     return AV_BSWAP32C(x);
        69. }
            ^
        70. #endif
        71. 

libavcodec/get_bits.h:233:5: 
      231.     OPEN_READER(re, s);
      232.     UPDATE_CACHE(re, s);
      233.     tmp = SHOW_UBITS(re, s, n);
               ^
      234.     LAST_SKIP_BITS(re, s, n);
      235.     CLOSE_READER(re, s);

libavcodec/get_bits.h:234:5: Condition is true
      232.     UPDATE_CACHE(re, s);
      233.     tmp = SHOW_UBITS(re, s, n);
      234.     LAST_SKIP_BITS(re, s, n);
               ^
      235.     CLOSE_READER(re, s);
      236.     return tmp;

libavcodec/get_bits.h:235:5: 
      233.     tmp = SHOW_UBITS(re, s, n);
      234.     LAST_SKIP_BITS(re, s, n);
      235.     CLOSE_READER(re, s);
               ^
      236.     return tmp;
      237. }

libavcodec/get_bits.h:236:5: 
      234.     LAST_SKIP_BITS(re, s, n);
      235.     CLOSE_READER(re, s);
      236.     return tmp;
               ^
      237. }
      238. 

libavcodec/get_bits.h:237:1: return from a call to get_bits
      235.     CLOSE_READER(re, s);
      236.     return tmp;
      237. }
           ^
      238. 
      239. /**

libavcodec/get_bits.h:302:9: 
    300. #else
    301.         int ret = get_bits(s, 16) << (n-16);
    302.         return ret | get_bits(s, n-16);
                 ^
    303. #endif
    304.     }

libavcodec/get_bits.h:228:1: start of procedure get_bits()
      226.  * Read 1-25 bits.
      227.  */
      228. static inline unsigned int get_bits(GetBitContext *s, int n)
           ^
      229. {
      230.     register int tmp;

libavcodec/get_bits.h:231:5: 
      229. {
      230.     register int tmp;
      231.     OPEN_READER(re, s);
               ^
      232.     UPDATE_CACHE(re, s);
      233.     tmp = SHOW_UBITS(re, s, n);

libavcodec/get_bits.h:232:5: 
      230.     register int tmp;
      231.     OPEN_READER(re, s);
      232.     UPDATE_CACHE(re, s);
               ^
      233.     tmp = SHOW_UBITS(re, s, n);
      234.     LAST_SKIP_BITS(re, s, n);

libavutil/bswap.h:66:1: start of procedure av_bswap32()
        64. 
        65. #ifndef av_bswap32
        66. static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
            ^
        67. {
        68.     return AV_BSWAP32C(x);

libavutil/bswap.h:68:5: 
        66. static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
        67. {
        68.     return AV_BSWAP32C(x);
                ^
        69. }
        70. #endif

libavutil/bswap.h:69:1: return from a call to av_bswap32
        67. {
        68.     return AV_BSWAP32C(x);
        69. }
            ^
        70. #endif
        71. 

libavcodec/get_bits.h:233:5: 
      231.     OPEN_READER(re, s);
      232.     UPDATE_CACHE(re, s);
      233.     tmp = SHOW_UBITS(re, s, n);
               ^
      234.     LAST_SKIP_BITS(re, s, n);
      235.     CLOSE_READER(re, s);

libavcodec/get_bits.h:234:5: Condition is true
      232.     UPDATE_CACHE(re, s);
      233.     tmp = SHOW_UBITS(re, s, n);
      234.     LAST_SKIP_BITS(re, s, n);
               ^
      235.     CLOSE_READER(re, s);
      236.     return tmp;

libavcodec/get_bits.h:235:5: 
      233.     tmp = SHOW_UBITS(re, s, n);
      234.     LAST_SKIP_BITS(re, s, n);
      235.     CLOSE_READER(re, s);
               ^
      236.     return tmp;
      237. }

libavcodec/get_bits.h:236:5: 
      234.     LAST_SKIP_BITS(re, s, n);
      235.     CLOSE_READER(re, s);
      236.     return tmp;
               ^
      237. }
      238. 

libavcodec/get_bits.h:237:1: return from a call to get_bits
      235.     CLOSE_READER(re, s);
      236.     return tmp;
      237. }
           ^
      238. 
      239. /**

libavcodec/get_bits.h:305:1: return from a call to get_bits_long
    303. #endif
    304.     }
    305. }
         ^
    306. 
    307. /**

libavcodec/get_bits.h:326:1: return from a call to show_bits_long
  324.         return get_bits_long(&gb, n);
  325.     }
  326. }
       ^
  327. 
  328. static inline int check_marker(GetBitContext *s, const char *msg)

libavcodec/mlpdec.c:984:9: Taking false branch
982. 
983.     m->is_major_sync_unit = 0;
984.     if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) {
             ^
985.         if (read_major_sync(m, &gb) < 0)
986.             goto error;

libavcodec/mlpdec.c:991:10: Taking false branch
989.     }
990. 
991.     if (!m->params_valid) {
              ^
992.         av_log(m->avctx, AV_LOG_WARNING,
993.                "Stream parameters not seen; skipping frame.\n");

libavcodec/mlpdec.c:998:5: 
 996.     }
 997. 
 998.     substream_start = 0;
          ^
 999. 
1000.     for (substr = 0; substr < m->num_substreams; substr++) {

libavcodec/mlpdec.c:1000:10: 
 998.     substream_start = 0;
 999. 
1000.     for (substr = 0; substr < m->num_substreams; substr++) {
               ^
1001.         int extraword_present, checkdata_present, end, nonrestart_substr;
1002. 

libavcodec/mlpdec.c:1000:22: Loop condition is true. Entering loop body
 998.     substream_start = 0;
 999. 
1000.     for (substr = 0; substr < m->num_substreams; substr++) {
                           ^
1001.         int extraword_present, checkdata_present, end, nonrestart_substr;
1002. 

libavcodec/mlpdec.c:1003:9: 
1001.         int extraword_present, checkdata_present, end, nonrestart_substr;
1002. 
1003.         extraword_present = get_bits1(&gb);
              ^
1004.         nonrestart_substr = get_bits1(&gb);
1005.         checkdata_present = get_bits1(&gb);

libavcodec/get_bits.h:259:1: start of procedure get_bits1()
  257. }
  258. 
  259. static inline unsigned int get_bits1(GetBitContext *s)
       ^
  260. {
  261.     unsigned int index = s->index;

libavcodec/get_bits.h:261:5: 
  259. static inline unsigned int get_bits1(GetBitContext *s)
  260. {
  261.     unsigned int index = s->index;
           ^
  262.     uint8_t result = s->buffer[index>>3];
  263. #ifdef ALT_BITSTREAM_READER_LE

libavcodec/get_bits.h:262:5: 
  260. {
  261.     unsigned int index = s->index;
  262.     uint8_t result = s->buffer[index>>3];
           ^
  263. #ifdef ALT_BITSTREAM_READER_LE
  264.     result >>= index & 7;

static int read_access_unit(AVCodecContext *avctx, void* data,
                            int *got_frame_ptr, AVPacket *avpkt)
{
    const uint8_t *buf = avpkt->data;
    int buf_size = avpkt->size;
    MLPDecodeContext *m = avctx->priv_data;
    GetBitContext gb;
    unsigned int length, substr;
    unsigned int substream_start;
    unsigned int header_size = 4;
    unsigned int substr_header_size = 0;
    uint8_t substream_parity_present[MAX_SUBSTREAMS];
    uint16_t substream_data_len[MAX_SUBSTREAMS];
    uint8_t parity_bits;
    int ret;
    if (buf_size < 4)
        return 0;
    length = (AV_RB16(buf) & 0xfff) * 2;
    if (length < 4 || length > buf_size)
        return AVERROR_INVALIDDATA;
    init_get_bits(&gb, (buf + 4), (length - 4) * 8);
    m->is_major_sync_unit = 0;
    if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) {
        if (read_major_sync(m, &gb) < 0)
            goto error;
        m->is_major_sync_unit = 1;
        header_size += 28;
    }
    if (!m->params_valid) {
        av_log(m->avctx, AV_LOG_WARNING,
               "Stream parameters not seen; skipping frame.\n");
        *got_frame_ptr = 0;
        return length;
    }
    substream_start = 0;
    for (substr = 0; substr < m->num_substreams; substr++) {
        int extraword_present, checkdata_present, end, nonrestart_substr;
        extraword_present = get_bits1(&gb);
        nonrestart_substr = get_bits1(&gb);
        checkdata_present = get_bits1(&gb);
        skip_bits1(&gb);
        end = get_bits(&gb, 12) * 2;
        substr_header_size += 2;
        if (extraword_present) {
            if (m->avctx->codec_id == CODEC_ID_MLP) {
                av_log(m->avctx, AV_LOG_ERROR, "There must be no extraword for MLP.\n");
                goto error;
            }
            skip_bits(&gb, 16);
            substr_header_size += 2;
        }
        if (!(nonrestart_substr ^ m->is_major_sync_unit)) {
            av_log(m->avctx, AV_LOG_ERROR, "Invalid nonrestart_substr.\n");
            goto error;
        }
        if (end + header_size + substr_header_size > length) {
            av_log(m->avctx, AV_LOG_ERROR,
                   "Indicated length of substream %d data goes off end of "
                   "packet.\n", substr);
            end = length - header_size - substr_header_size;
        }
        if (end < substream_start) {
            av_log(avctx, AV_LOG_ERROR,
                   "Indicated end offset of substream %d data "
                   "is smaller than calculated start offset.\n",
                   substr);
            goto error;
        }
        if (substr > m->max_decoded_substream)
            continue;
        substream_parity_present[substr] = checkdata_present;
        substream_data_len[substr] = end - substream_start;
        substream_start = end;
    }
    parity_bits  = ff_mlp_calculate_parity(buf, 4);
    parity_bits ^= ff_mlp_calculate_parity(buf + header_size, substr_header_size);
    if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {
        av_log(avctx, AV_LOG_ERROR, "Parity check failed.\n");
        goto error;
    }
    buf += header_size + substr_header_size;
    for (substr = 0; substr <= m->max_decoded_substream; substr++) {
        SubStream *s = &m->substream[substr];
        init_get_bits(&gb, buf, substream_data_len[substr] * 8);
        m->matrix_changed = 0;
        memset(m->filter_changed, 0, sizeof(m->filter_changed));
        s->blockpos = 0;
        do {
            if (get_bits1(&gb)) {
                if (get_bits1(&gb)) {
                    if (read_restart_header(m, &gb, buf, substr) < 0)
                        goto next_substr;
                    s->restart_seen = 1;
                }
                if (!s->restart_seen)
                    goto next_substr;
                if (read_decoding_params(m, &gb, substr) < 0)
                    goto next_substr;
            }
            if (!s->restart_seen)
                goto next_substr;
            if ((ret = read_block_data(m, &gb, substr)) < 0)
                return ret;
            if (get_bits_count(&gb) >= substream_data_len[substr] * 8)
                goto substream_length_mismatch;
        } while (!get_bits1(&gb));
        skip_bits(&gb, (-get_bits_count(&gb)) & 15);
        if (substream_data_len[substr] * 8 - get_bits_count(&gb) >= 32) {
            int shorten_by;
            if (get_bits(&gb, 16) != 0xD234)
                return AVERROR_INVALIDDATA;
            shorten_by = get_bits(&gb, 16);
            if      (m->avctx->codec_id == CODEC_ID_TRUEHD && shorten_by  & 0x2000)
                s->blockpos -= FFMIN(shorten_by & 0x1FFF, s->blockpos);
            else if (m->avctx->codec_id == CODEC_ID_MLP    && shorten_by != 0xD234)
                return AVERROR_INVALIDDATA;
            if (substr == m->max_decoded_substream)
                av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\n");
        }
        if (substream_parity_present[substr]) {
            uint8_t parity, checksum;
            if (substream_data_len[substr] * 8 - get_bits_count(&gb) != 16)
                goto substream_length_mismatch;
            parity   = ff_mlp_calculate_parity(buf, substream_data_len[substr] - 2);
            checksum = ff_mlp_checksum8       (buf, substream_data_len[substr] - 2);
            if ((get_bits(&gb, 8) ^ parity) != 0xa9    )
                av_log(m->avctx, AV_LOG_ERROR, "Substream %d parity check failed.\n", substr);
            if ( get_bits(&gb, 8)           != checksum)
                av_log(m->avctx, AV_LOG_ERROR, "Substream %d checksum failed.\n"    , substr);
        }
        if (substream_data_len[substr] * 8 != get_bits_count(&gb))
            goto substream_length_mismatch;
next_substr:
        if (!s->restart_seen)
            av_log(m->avctx, AV_LOG_ERROR,
                   "No restart header present in substream %d.\n", substr);
        buf += substream_data_len[substr];
    }
    rematrix_channels(m, m->max_decoded_substream);
    if ((ret = output_data(m, m->max_decoded_substream, data, got_frame_ptr)) < 0)
        return ret;
    return length;
substream_length_mismatch:
    av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\n", substr);
    return AVERROR_INVALIDDATA;
error:
    m->params_valid = 0;
    return AVERROR_INVALIDDATA;
}
['static int read_access_unit(AVCodecContext *avctx, void* data,\n                            int *got_frame_ptr, AVPacket *avpkt)\n{\n    const uint8_t *buf = avpkt->data;\n    int buf_size = avpkt->size;\n    MLPDecodeContext *m = avctx->priv_data;\n    GetBitContext gb;\n    unsigned int length, substr;\n    unsigned int substream_start;\n    unsigned int header_size = 4;\n    unsigned int substr_header_size = 0;\n    uint8_t substream_parity_present[MAX_SUBSTREAMS];\n    uint16_t substream_data_len[MAX_SUBSTREAMS];\n    uint8_t parity_bits;\n    int ret;\n    if (buf_size < 4)\n        return 0;\n    length = (AV_RB16(buf) & 0xfff) * 2;\n    if (length < 4 || length > buf_size)\n        return AVERROR_INVALIDDATA;\n    init_get_bits(&gb, (buf + 4), (length - 4) * 8);\n    m->is_major_sync_unit = 0;\n    if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) {\n        if (read_major_sync(m, &gb) < 0)\n            goto error;\n        m->is_major_sync_unit = 1;\n        header_size += 28;\n    }\n    if (!m->params_valid) {\n        av_log(m->avctx, AV_LOG_WARNING,\n               "Stream parameters not seen; skipping frame.\\n");\n        *got_frame_ptr = 0;\n        return length;\n    }\n    substream_start = 0;\n    for (substr = 0; substr < m->num_substreams; substr++) {\n        int extraword_present, checkdata_present, end, nonrestart_substr;\n        extraword_present = get_bits1(&gb);\n        nonrestart_substr = get_bits1(&gb);\n        checkdata_present = get_bits1(&gb);\n        skip_bits1(&gb);\n        end = get_bits(&gb, 12) * 2;\n        substr_header_size += 2;\n        if (extraword_present) {\n            if (m->avctx->codec_id == CODEC_ID_MLP) {\n                av_log(m->avctx, AV_LOG_ERROR, "There must be no extraword for MLP.\\n");\n                goto error;\n            }\n            skip_bits(&gb, 16);\n            substr_header_size += 2;\n        }\n        if (!(nonrestart_substr ^ m->is_major_sync_unit)) {\n            av_log(m->avctx, AV_LOG_ERROR, "Invalid nonrestart_substr.\\n");\n            goto error;\n        }\n        if (end + header_size + substr_header_size > length) {\n            av_log(m->avctx, AV_LOG_ERROR,\n                   "Indicated length of substream %d data goes off end of "\n                   "packet.\\n", substr);\n            end = length - header_size - substr_header_size;\n        }\n        if (end < substream_start) {\n            av_log(avctx, AV_LOG_ERROR,\n                   "Indicated end offset of substream %d data "\n                   "is smaller than calculated start offset.\\n",\n                   substr);\n            goto error;\n        }\n        if (substr > m->max_decoded_substream)\n            continue;\n        substream_parity_present[substr] = checkdata_present;\n        substream_data_len[substr] = end - substream_start;\n        substream_start = end;\n    }\n    parity_bits  = ff_mlp_calculate_parity(buf, 4);\n    parity_bits ^= ff_mlp_calculate_parity(buf + header_size, substr_header_size);\n    if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {\n        av_log(avctx, AV_LOG_ERROR, "Parity check failed.\\n");\n        goto error;\n    }\n    buf += header_size + substr_header_size;\n    for (substr = 0; substr <= m->max_decoded_substream; substr++) {\n        SubStream *s = &m->substream[substr];\n        init_get_bits(&gb, buf, substream_data_len[substr] * 8);\n        m->matrix_changed = 0;\n        memset(m->filter_changed, 0, sizeof(m->filter_changed));\n        s->blockpos = 0;\n        do {\n            if (get_bits1(&gb)) {\n                if (get_bits1(&gb)) {\n                    if (read_restart_header(m, &gb, buf, substr) < 0)\n                        goto next_substr;\n                    s->restart_seen = 1;\n                }\n                if (!s->restart_seen)\n                    goto next_substr;\n                if (read_decoding_params(m, &gb, substr) < 0)\n                    goto next_substr;\n            }\n            if (!s->restart_seen)\n                goto next_substr;\n            if ((ret = read_block_data(m, &gb, substr)) < 0)\n                return ret;\n            if (get_bits_count(&gb) >= substream_data_len[substr] * 8)\n                goto substream_length_mismatch;\n        } while (!get_bits1(&gb));\n        skip_bits(&gb, (-get_bits_count(&gb)) & 15);\n        if (substream_data_len[substr] * 8 - get_bits_count(&gb) >= 32) {\n            int shorten_by;\n            if (get_bits(&gb, 16) != 0xD234)\n                return AVERROR_INVALIDDATA;\n            shorten_by = get_bits(&gb, 16);\n            if      (m->avctx->codec_id == CODEC_ID_TRUEHD && shorten_by  & 0x2000)\n                s->blockpos -= FFMIN(shorten_by & 0x1FFF, s->blockpos);\n            else if (m->avctx->codec_id == CODEC_ID_MLP    && shorten_by != 0xD234)\n                return AVERROR_INVALIDDATA;\n            if (substr == m->max_decoded_substream)\n                av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\\n");\n        }\n        if (substream_parity_present[substr]) {\n            uint8_t parity, checksum;\n            if (substream_data_len[substr] * 8 - get_bits_count(&gb) != 16)\n                goto substream_length_mismatch;\n            parity   = ff_mlp_calculate_parity(buf, substream_data_len[substr] - 2);\n            checksum = ff_mlp_checksum8       (buf, substream_data_len[substr] - 2);\n            if ((get_bits(&gb, 8) ^ parity) != 0xa9    )\n                av_log(m->avctx, AV_LOG_ERROR, "Substream %d parity check failed.\\n", substr);\n            if ( get_bits(&gb, 8)           != checksum)\n                av_log(m->avctx, AV_LOG_ERROR, "Substream %d checksum failed.\\n"    , substr);\n        }\n        if (substream_data_len[substr] * 8 != get_bits_count(&gb))\n            goto substream_length_mismatch;\nnext_substr:\n        if (!s->restart_seen)\n            av_log(m->avctx, AV_LOG_ERROR,\n                   "No restart header present in substream %d.\\n", substr);\n        buf += substream_data_len[substr];\n    }\n    rematrix_channels(m, m->max_decoded_substream);\n    if ((ret = output_data(m, m->max_decoded_substream, data, got_frame_ptr)) < 0)\n        return ret;\n    return length;\nsubstream_length_mismatch:\n    av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\\n", substr);\n    return AVERROR_INVALIDDATA;\nerror:\n    m->params_valid = 0;\n    return AVERROR_INVALIDDATA;\n}', 'static av_always_inline av_const uint16_t av_bswap16(uint16_t x)\n{\n    x= (x>>8) | (x<<8);\n    return x;\n}', 'static inline void init_get_bits(GetBitContext *s, const uint8_t *buffer,\n                                 int bit_size)\n{\n    int buffer_size = (bit_size+7)>>3;\n    if (buffer_size < 0 || bit_size < 0) {\n        buffer_size = bit_size = 0;\n        buffer = NULL;\n    }\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}', 'static inline unsigned int show_bits_long(GetBitContext *s, int n)\n{\n    if (n <= MIN_CACHE_BITS)\n        return show_bits(s, n);\n    else {\n        GetBitContext gb = *s;\n        return get_bits_long(&gb, n);\n    }\n}', 'static inline unsigned int get_bits_long(GetBitContext *s, int n)\n{\n    if (n <= MIN_CACHE_BITS)\n        return get_bits(s, n);\n    else {\n#ifdef ALT_BITSTREAM_READER_LE\n        int ret = get_bits(s, 16);\n        return ret | (get_bits(s, n-16) << 16);\n#else\n        int ret = get_bits(s, 16) << (n-16);\n        return ret | get_bits(s, n-16);\n#endif\n    }\n}', 'static inline unsigned int get_bits(GetBitContext *s, int n)\n{\n    register int tmp;\n    OPEN_READER(re, s);\n    UPDATE_CACHE(re, s);\n    tmp = SHOW_UBITS(re, s, n);\n    LAST_SKIP_BITS(re, s, n);\n    CLOSE_READER(re, s);\n    return tmp;\n}', 'static av_always_inline av_const uint32_t av_bswap32(uint32_t x)\n{\n    return AV_BSWAP32C(x);\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 ALT_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}']