# HG changeset patch # User reimar # Date 1165868316 0 # Node ID c5f74ebdba348b6e70d537bed52a10f59e79d111 # Parent 4bfaef73d6edf05659e0d92bc27afeaa17fd044e Fix JPEG-LS encoder 0xff-escaping writing too much or uninitialized data. diff -r 4bfaef73d6ed -r c5f74ebdba34 jpeg_ls.c --- a/jpeg_ls.c Mon Dec 11 15:53:55 2006 +0000 +++ b/jpeg_ls.c Mon Dec 11 20:18:36 2006 +0000 @@ -804,11 +804,16 @@ av_free(zero); av_free(state); + // the specification says that after doing 0xff escaping unused bits in the + // last byte must be set to 0, so just append 7 "optional" zero-bits to + // avoid special-casing. + put_bits(&pb2, 7, 0); + size = put_bits_count(&pb2); flush_put_bits(&pb2); /* do escape coding */ - size = put_bits_count(&pb2) >> 3; init_get_bits(&gb, buf2, size); - while(get_bits_count(&gb) < size * 8){ + size -= 7; + while(get_bits_count(&gb) < size){ int v; v = get_bits(&gb, 8); put_bits(&pb, 8, v);