changeset 4297:c5f74ebdba34 libavcodec

Fix JPEG-LS encoder 0xff-escaping writing too much or uninitialized data.
author reimar
date Mon, 11 Dec 2006 20:18:36 +0000
parents 4bfaef73d6ed
children bba6e75e026b
files jpeg_ls.c
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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);