[Swfdec] 3 commits - libswfdec/swfdec_bits.c
libswfdec/swfdec_bits.h libswfdec/swfdec_sprite.c
libswfdec/swfdec_tag.c
Benjamin Otte
company at kemper.freedesktop.org
Wed Mar 28 06:15:53 PDT 2007
libswfdec/swfdec_bits.c | 81 +++++++++++++++++++++++++++++-----------------
libswfdec/swfdec_bits.h | 1
libswfdec/swfdec_sprite.c | 6 ---
libswfdec/swfdec_tag.c | 12 ------
4 files changed, 55 insertions(+), 45 deletions(-)
New commits:
diff-tree 493905baa1c07054276adb078f086e7ca4acc26b (from parents)
Merge: 3dc137aafb42e15340c20a78d1599c714862ba0f 5aa91da71e7235fe7e8507f30de3bb207838bb2c
Author: Benjamin Otte <otte at gnome.org>
Date: Tue Mar 27 13:50:19 2007 +0200
Merge branch 'master' of ssh://company@git.freedesktop.org/git/swfdec
diff-tree 3dc137aafb42e15340c20a78d1599c714862ba0f (from 49e51702c80e2304918b74b897638948a507b4bd)
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Mar 23 14:24:12 2007 +0100
Add function swfdec_bits_init_bits
It's a shortcut for swfdec_bits_init (bits, swfdec_bits_get_buffer (from, length));
diff --git a/libswfdec/swfdec_bits.c b/libswfdec/swfdec_bits.c
index ff863cc..46b0581 100644
--- a/libswfdec/swfdec_bits.c
+++ b/libswfdec/swfdec_bits.c
@@ -32,6 +32,25 @@
#include "swfdec_rect.h"
+#define SWFDEC_BITS_CHECK(b,n) G_STMT_START { \
+ if (swfdec_bits_left(b) < (n)) { \
+ SWFDEC_ERROR ("reading past end of buffer"); \
+ b->ptr = b->end; \
+ b->idx = 0; \
+ return 0; \
+ } \
+}G_STMT_END
+#define SWFDEC_BYTES_CHECK(b,n) G_STMT_START { \
+ g_assert (b->end >= b->ptr); \
+ g_assert (b->idx == 0); \
+ if ((unsigned long) (b->end - b->ptr) < n) { \
+ SWFDEC_ERROR ("reading past end of buffer"); \
+ b->ptr = b->end; \
+ b->idx = 0; \
+ return 0; \
+ } \
+} G_STMT_END
+
/**
* swfdec_bits_init:
* @bits: a #SwfdecBits
@@ -56,6 +75,32 @@ swfdec_bits_init (SwfdecBits *bits, Swfd
}
/**
+ * swfdec_bits_init_bits:
+ * @bits: a #SwfdecBits
+ * @from: a #SwfdecBits to initialize from
+ * @bytes: number of bytes to move to @bits
+ *
+ * Initializes @bits for use with the next @bytes bytes from @from. If not
+ * enough bytes are available, less bytes will be available in @bits. @from
+ * will skip the bytes now available in @bits. If you want to know if this
+ * function moves enough bytes, you should ensure that enough data is
+ * available using swfdec_bits_left() before calling this function.
+ **/
+void
+swfdec_bits_init_bits (SwfdecBits *bits, SwfdecBits *from, unsigned int bytes)
+{
+ g_return_if_fail (bits != NULL);
+ g_return_if_fail (from != NULL);
+ g_return_if_fail (from->idx == 0);
+
+ bits->buffer = from->buffer;
+ bits->ptr = from->ptr;
+ bits->end = MIN (bits->ptr + bytes, from->end);
+ bits->idx = 0;
+ from->ptr = bits->end;
+}
+
+/**
* swfdec_bits_init_data:
* @bits: the #SwfdecBits to initialize
* @data: data to initialize with
@@ -87,25 +132,6 @@ swfdec_bits_left (SwfdecBits *b)
return (b->end - b->ptr) * 8 - b->idx;
}
-#define SWFDEC_BITS_CHECK(b,n) G_STMT_START { \
- if (swfdec_bits_left(b) < (n)) { \
- SWFDEC_ERROR ("reading past end of buffer"); \
- b->ptr = b->end; \
- b->idx = 0; \
- return 0; \
- } \
-}G_STMT_END
-#define SWFDEC_BYTES_CHECK(b,n) G_STMT_START { \
- g_assert (b->end >= b->ptr); \
- g_assert (b->idx == 0); \
- if ((unsigned long) (b->end - b->ptr) < n) { \
- SWFDEC_ERROR ("reading past end of buffer"); \
- b->ptr = b->end; \
- b->idx = 0; \
- return 0; \
- } \
-} G_STMT_END
-
int
swfdec_bits_getbit (SwfdecBits * b)
{
diff --git a/libswfdec/swfdec_bits.h b/libswfdec/swfdec_bits.h
index ac07746..4f7b20a 100644
--- a/libswfdec/swfdec_bits.h
+++ b/libswfdec/swfdec_bits.h
@@ -38,6 +38,7 @@ struct _SwfdecBits
void swfdec_bits_init (SwfdecBits *bits, SwfdecBuffer *buffer);
void swfdec_bits_init_data (SwfdecBits *bits, const guint8 *data, guint len);
+void swfdec_bits_init_bits (SwfdecBits *bits, SwfdecBits *from, unsigned int bytes);
unsigned int swfdec_bits_left (SwfdecBits *b);
int swfdec_bits_getbit (SwfdecBits * b);
unsigned int swfdec_bits_getbits (SwfdecBits * b, unsigned int n);
diff --git a/libswfdec/swfdec_sprite.c b/libswfdec/swfdec_sprite.c
index 8bbc7c9..a993ece 100644
--- a/libswfdec/swfdec_sprite.c
+++ b/libswfdec/swfdec_sprite.c
@@ -420,11 +420,8 @@ swfdec_spriteseg_place_object_2 (SwfdecS
while ((event_flags = swfdec_get_clipeventflags (s, bits)) != 0) {
guint length = swfdec_bits_get_u32 (bits);
SwfdecBits action_bits;
- SwfdecBuffer *buffer = swfdec_bits_get_buffer (bits, length);
- if (buffer == NULL)
- break;
- swfdec_bits_init (&action_bits, buffer);
+ swfdec_bits_init_bits (&action_bits, bits, length);
if (event_flags & SWFDEC_EVENT_KEY_PRESS)
key_code = swfdec_bits_get_u8 (&action_bits);
else
@@ -445,7 +442,6 @@ swfdec_spriteseg_place_object_2 (SwfdecS
SWFDEC_ERROR ("not all action data was parsed: %u bytes left",
swfdec_bits_left (&action_bits));
}
- swfdec_buffer_unref (buffer);
}
g_free (script_name);
}
diff --git a/libswfdec/swfdec_tag.c b/libswfdec/swfdec_tag.c
index 255f6c3..edec808 100644
--- a/libswfdec/swfdec_tag.c
+++ b/libswfdec/swfdec_tag.c
@@ -212,7 +212,6 @@ tag_func_define_sprite (SwfdecSwfDecoder
do {
int x;
guint tag_len;
- SwfdecBuffer *buffer;
SwfdecTagFunc *func;
x = swfdec_bits_get_u16 (&parse);
@@ -226,16 +225,9 @@ tag_func_define_sprite (SwfdecSwfDecoder
swfdec_swf_decoder_get_tag_name (tag), tag_len);
if (tag_len == 0) {
- buffer = NULL;
swfdec_bits_init_data (&s->b, NULL, 0);
} else {
- buffer = swfdec_bits_get_buffer (&parse, tag_len);
- if (buffer == NULL) {
- SWFDEC_ERROR ("tag claims to be %u bytes long, but not enough bytes remaining",
- tag_len);
- break;
- }
- swfdec_bits_init (&s->b, buffer);
+ swfdec_bits_init_bits (&s->b, &parse, tag_len);
}
func = swfdec_swf_decoder_get_tag_func (tag);
@@ -253,8 +245,6 @@ tag_func_define_sprite (SwfdecSwfDecoder
swfdec_bits_left (&s->b) / 8);
}
}
- if (buffer)
- swfdec_buffer_unref (buffer);
} while (tag != 0);
diff-tree 49e51702c80e2304918b74b897638948a507b4bd (from 20fce106dfb4e4f314fa9ed2eb639448a0b5d854)
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Mar 23 14:03:09 2007 +0100
change semantics of SwfdecBits.idx handling
previously functions reading whole bytes called swfdec_bits_syncbits before
doing any reading. Now everyone using SwfdecBits for reading bits is
responsible for syncing when they want to resume reading bytes. The byte
reading code asserts that bits->idx == 0.
This change may introduce segfaults with code that isn't yet canged to call
swfdec_bits_syncbits() manually.
diff --git a/libswfdec/swfdec_bits.c b/libswfdec/swfdec_bits.c
index a90ba96..ff863cc 100644
--- a/libswfdec/swfdec_bits.c
+++ b/libswfdec/swfdec_bits.c
@@ -96,11 +96,9 @@ swfdec_bits_left (SwfdecBits *b)
} \
}G_STMT_END
#define SWFDEC_BYTES_CHECK(b,n) G_STMT_START { \
- gulong __bytes; \
- swfdec_bits_syncbits (b); \
- __bytes = b->end - b->ptr; \
- if (!(__bytes > n || \
- (__bytes == n && b->idx == 0))) { \
+ g_assert (b->end >= b->ptr); \
+ g_assert (b->idx == 0); \
+ if ((unsigned long) (b->end - b->ptr) < n) { \
SWFDEC_ERROR ("reading past end of buffer"); \
b->ptr = b->end; \
b->idx = 0; \
@@ -370,7 +368,6 @@ swfdec_bits_get_color_transform (SwfdecB
int has_mult;
int n_bits;
- swfdec_bits_syncbits (bits);
has_add = swfdec_bits_getbit (bits);
has_mult = swfdec_bits_getbit (bits);
n_bits = swfdec_bits_getbits (bits, 4);
@@ -396,6 +393,7 @@ swfdec_bits_get_color_transform (SwfdecB
ct->bb = 0;
ct->ab = 0;
}
+ swfdec_bits_syncbits (bits);
}
void
@@ -406,8 +404,6 @@ swfdec_bits_get_matrix (SwfdecBits * bit
int has_rotate;
int n_translate_bits;
- swfdec_bits_syncbits (bits);
-
has_scale = swfdec_bits_getbit (bits);
if (has_scale) {
int n_scale_bits = swfdec_bits_getbits (bits, 5);
@@ -440,6 +436,7 @@ swfdec_bits_get_matrix (SwfdecBits * bit
matrix->y0 = swfdec_bits_getsbits (bits, n_translate_bits);
swfdec_matrix_ensure_invertible (matrix, inverse);
+ swfdec_bits_syncbits (bits);
}
char *
@@ -488,7 +485,7 @@ swfdec_bits_skip_string (SwfdecBits *bit
guint
swfdec_bits_skip_bytes (SwfdecBits *bits, guint n_bytes)
{
- swfdec_bits_syncbits (bits);
+ g_assert (bits->idx == 0);
if ((guint) (bits->end - bits->ptr) < n_bytes) {
SWFDEC_WARNING ("supposed to skip %u bytes, but only %td available",
n_bytes, bits->end - bits->ptr);
@@ -597,13 +594,13 @@ swfdec_bits_get_rect (SwfdecBits * bits,
{
int nbits;
- swfdec_bits_syncbits (bits);
nbits = swfdec_bits_getbits (bits, 5);
-
rect->x0 = swfdec_bits_getsbits (bits, nbits);
rect->x1 = swfdec_bits_getsbits (bits, nbits);
rect->y0 = swfdec_bits_getsbits (bits, nbits);
rect->y1 = swfdec_bits_getsbits (bits, nbits);
+
+ swfdec_bits_syncbits (bits);
}
/**
@@ -627,7 +624,7 @@ swfdec_bits_get_buffer (SwfdecBits *bits
if (len > 0) {
SWFDEC_BYTES_CHECK (bits, (unsigned int) len);
} else {
- swfdec_bits_syncbits (bits);
+ g_assert (bits->idx == 0);
len = bits->end - bits->ptr;
g_assert (len >= 0);
}
@@ -685,7 +682,7 @@ swfdec_bits_decompress (SwfdecBits *bits
if (compressed > 0) {
SWFDEC_BYTES_CHECK (bits, (unsigned int) compressed);
} else {
- swfdec_bits_syncbits (bits);
+ g_assert (bits->idx == 0);
compressed = bits->end - bits->ptr;
g_assert (compressed >= 0);
}
More information about the Swfdec
mailing list