Return error from cabac init if offset is greater than range

When the offset was greater than range, the bitstream was read
more than the valid range in leaf-level cabac parsing modules.
Error check was added to cabac init to fix this issue. Additionally
end of slice and slice error were signalled to suppress further
parsing of current slice.

Bug: 34897036
Change-Id: I1263f1d1219684ffa6e952c76e5a08e9a933c9d2
(cherry picked from commit 3b175da88a1807d19cdd248b74bce60e57f05c6a)
(cherry picked from commit b92314c860d01d754ef579eafe55d7377962b3ba)

UWORD32 ihevcd_cabac_decode_terminate(cab_ctxt_t *ps_cabac,
 bitstrm_t *ps_bitstrm)
{
    UWORD32 u4_range = ps_cabac->u4_range;
    UWORD32 u4_ofst = ps_cabac->u4_ofst;
    UWORD32 u4_bin;
#if FULLRANGE
    WORD32 clz;
#endif
 /* Sanity checks */
    ASSERT(u4_range >= 256);
#if FULLRANGE
    clz = CLZ(u4_range);
    clz -= (32 - RANGE_NUMBITS);
    u4_range -= 2 << (RANGE_SHIFT - clz);
#else
    u4_range -= 2;
#endif

 if(u4_ofst >= u4_range)
 {
        u4_bin = 1;

#if FULLRANGE
 /* In case of FULLRANGE extra bits read earlier need to pushed back to the bitstream */
 {
            WORD32 clz;
            WORD32 numbits;
            clz = CLZ(ps_cabac->u4_range);

            numbits = (32 - clz);
            numbits -= 9;

            ihevcd_bits_seek(ps_bitstrm, -numbits);
 }
#endif

 }
 else
 {
        u4_bin = 0;
 }
 if(0 == u4_bin)
 {
        UWORD32 u4_bits;
        WORD32 numbits;
        numbits = CLZ(u4_range);
        numbits -= (32 - RANGE_NUMBITS);
#if !FULLRANGE
        numbits -= RANGE_SHIFT;
#endif
 /* Renormalize if required */
 if(numbits)
 {
            BITS_GET(u4_bits, ps_bitstrm->pu4_buf, ps_bitstrm->u4_bit_ofst,
                     ps_bitstrm->u4_cur_word, ps_bitstrm->u4_nxt_word, numbits);

            u4_ofst <<= numbits;
            u4_ofst |= u4_bits;
            u4_range <<= numbits;
 }
 }
 /* bits to be inserted in the bitstream */
    ps_cabac->u4_range = u4_range;
    ps_cabac->u4_ofst = u4_ofst;
    DEBUG_RANGE_OFST("term", ps_cabac->u4_range, ps_cabac->u4_ofst);

 return (u4_bin);
}

UWORD32 ihevcd_cabac_decode_terminate(cab_ctxt_t *ps_cabac,
 bitstrm_t *ps_bitstrm)
{
    UWORD32 u4_range = ps_cabac->u4_range;
    UWORD32 u4_ofst = ps_cabac->u4_ofst;
    UWORD32 u4_bin;
#if FULLRANGE
    WORD32 clz;
#endif
 /* Sanity checks */
    ASSERT(u4_range >= 256);
#if FULLRANGE
    clz = CLZ(u4_range);
    clz -= (32 - RANGE_NUMBITS);
    u4_range -= 2 << (RANGE_SHIFT - clz);
#else
    u4_range -= 2;
#endif

 if(u4_ofst >= u4_range)
 {
        u4_bin = 1;

#if FULLRANGE
 /* In case of FULLRANGE extra bits read earlier need to pushed back to the bitstream */
 {
            WORD32 clz;
            WORD32 numbits;
            clz = CLZ(ps_cabac->u4_range);

            numbits = (32 - clz);
            numbits -= 9;

            ihevcd_bits_seek(ps_bitstrm, -numbits);
 }
#endif

 }
 else
 {
        u4_bin = 0;
 }
 if(0 == u4_bin)
 {
        UWORD32 u4_bits;
        WORD32 numbits;
        numbits = CLZ(u4_range);
        numbits -= (32 - RANGE_NUMBITS);
#if !FULLRANGE
        numbits -= RANGE_SHIFT;
#endif
 /* Renormalize if required */
 if(numbits)
 {
            BITS_GET(u4_bits, ps_bitstrm->pu4_buf, ps_bitstrm->u4_bit_ofst,
                     ps_bitstrm->u4_cur_word, ps_bitstrm->u4_nxt_word, numbits);

            u4_ofst <<= numbits;
            u4_ofst |= u4_bits;
            u4_range <<= numbits;
 }
 }
 /* bits to be inserted in the bitstream */
    ps_cabac->u4_range = u4_range;
    ps_cabac->u4_ofst = u4_ofst;
    DEBUG_RANGE_OFST("term", ps_cabac->u4_range, ps_cabac->u4_ofst);

 return (u4_bin);
}
