From: Jaroslav Kysela Date: Thu, 24 Sep 2015 21:41:04 +0000 (+0200) Subject: parser h264: fix h264_nal_deescape regression X-Git-Tag: v4.2.1~2059 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a70bdf336f7f4f304ea0652c16ac1586da55a6ed;p=thirdparty%2Ftvheadend.git parser h264: fix h264_nal_deescape regression --- diff --git a/src/parsers/parser_h264.c b/src/parsers/parser_h264.c index bbad3d86d..94bc1b3ac 100644 --- a/src/parsers/parser_h264.c +++ b/src/parsers/parser_h264.c @@ -43,35 +43,38 @@ void * h264_nal_deescape(bitstream_t *bs, const uint8_t *data, int size) { - int_fast32_t i = 0; uint_fast8_t c; uint8_t *d; + const uint8_t *end, *end2; bs->rdata = d = malloc(size); bs->offset = 0; + end2 = data + size; + if (size > 2) { - /* Escape 0x000003 into 0x0000 */ + /* Escape 0x000003 into 0x0000 */ - for( ; i < size - 2; i++) { + end = end2 - 2; + while (data < end) { c = *data++; - if (c || data[1] || data[2] != 3) { + if (c || *data || *(data + 1) != 3) { *d++ = c; - continue; + } else { + *d++ = 0; + *d++ = 0; + data += 2; } - *d++ = 0; - *d++ = 0; - i+= 2; } } - for (; i < size; i++) + while (data < end2) *d++ = *data++; bs->len = (d - bs->rdata) * 8; - return d; + return (void *)bs->rdata; }