[Swfdec] libswfdec/swfdec_amf.c libswfdec/swfdec_bits.c libswfdec/swfdec_bits.h libswfdec/swfdec_font.c
Benjamin Otte
company at kemper.freedesktop.org
Thu Nov 22 14:29:58 PST 2007
libswfdec/swfdec_amf.c | 3 ++-
libswfdec/swfdec_bits.c | 24 +++++++++++++++++-------
libswfdec/swfdec_bits.h | 2 +-
libswfdec/swfdec_font.c | 6 +++---
4 files changed, 23 insertions(+), 12 deletions(-)
New commits:
commit cefea31ed3225dfbebc01877963db6d27ce83016
Author: Andreas Henriksson <andreas at fatal.se>
Date: Thu Nov 22 23:29:50 2007 +0100
make swfdec_bits_get_string_length() version-aware
diff --git a/libswfdec/swfdec_amf.c b/libswfdec/swfdec_amf.c
index a53e761..4baab41 100644
--- a/libswfdec/swfdec_amf.c
+++ b/libswfdec/swfdec_amf.c
@@ -48,7 +48,8 @@ swfdec_amf_parse_string (SwfdecAsContext *context, SwfdecBits *bits, SwfdecAsVal
guint len = swfdec_bits_get_bu16 (bits);
char *s;
- s = swfdec_bits_get_string_length (bits, len);
+ /* FIXME: the supplied version is likely incorrect */
+ s = swfdec_bits_get_string_length (bits, len, context->version);
if (s == NULL)
return FALSE;
SWFDEC_AS_VALUE_SET_STRING (val, swfdec_as_context_give_string (context, s));
diff --git a/libswfdec/swfdec_bits.c b/libswfdec/swfdec_bits.c
index fbc35fc..edc79a8 100644
--- a/libswfdec/swfdec_bits.c
+++ b/libswfdec/swfdec_bits.c
@@ -543,13 +543,15 @@ swfdec_bits_skip_bytes (SwfdecBits *bits, guint n_bytes)
* swfdec_bits_get_string_length:
* @bits: a #SwfdecBits
* @len: number of bytes to read
+ * @version: flash version number
*
- * Reads the next @len bytes into a string and validates it as UTF-8.
+ * Reads the next @len bytes (not characters!) into a string and validates
+ * its encoding is correct based on supplied version number.
*
- * Returns: a new string or %NULL on error
+ * Returns: a new UTF-8 string or %NULL on error
**/
char *
-swfdec_bits_get_string_length (SwfdecBits * bits, guint len)
+swfdec_bits_get_string_length (SwfdecBits * bits, guint len, guint version)
{
char *ret;
@@ -559,11 +561,19 @@ swfdec_bits_get_string_length (SwfdecBits * bits, guint len)
ret = g_strndup ((char *) bits->ptr, len);
bits->ptr += len;
- if (!g_utf8_validate (ret, -1, NULL)) {
- SWFDEC_ERROR ("parsed string is not valid utf-8");
- g_free (ret);
- ret = NULL;
+
+ if (version < 6) {
+ char *tmp = g_convert (ret, -1, "UTF-8", "LATIN1", NULL , NULL, NULL);
+ g_free(ret);
+ ret = tmp;
+ } else {
+ if (!g_utf8_validate (ret, -1, NULL)) {
+ SWFDEC_ERROR ("parsed string is not valid utf-8");
+ g_free (ret);
+ ret = NULL;
+ }
}
+
return ret;
}
diff --git a/libswfdec/swfdec_bits.h b/libswfdec/swfdec_bits.h
index 29e9cce..c56bc99 100644
--- a/libswfdec/swfdec_bits.h
+++ b/libswfdec/swfdec_bits.h
@@ -62,7 +62,7 @@ void swfdec_bits_get_color_transform (SwfdecBits * bits,
void swfdec_bits_get_matrix (SwfdecBits * bits, cairo_matrix_t *matrix,
cairo_matrix_t *inverse);
guint swfdec_bits_skip_bytes (SwfdecBits *bits, guint bytes);
-char *swfdec_bits_get_string_length (SwfdecBits * bits, guint len);
+char *swfdec_bits_get_string_length (SwfdecBits * bits, guint len, guint version);
char *swfdec_bits_get_string (SwfdecBits *bits, guint version);
SwfdecColor swfdec_bits_get_color (SwfdecBits * bits);
SwfdecColor swfdec_bits_get_rgba (SwfdecBits * bits);
diff --git a/libswfdec/swfdec_font.c b/libswfdec/swfdec_font.c
index 02385dc..bce8792 100644
--- a/libswfdec/swfdec_font.c
+++ b/libswfdec/swfdec_font.c
@@ -143,7 +143,7 @@ tag_func_define_font_info (SwfdecSwfDecoder *s, guint tag)
}
len = swfdec_bits_get_u8 (&s->b);
/* this string is locale specific */
- name = swfdec_bits_get_string_length (&s->b, len);
+ name = swfdec_bits_get_string_length (&s->b, len, s->version);
reserved = swfdec_bits_getbits (&s->b, 2);
font->small = swfdec_bits_getbit (&s->b);
jis = swfdec_bits_getbit (&s->b);
@@ -307,7 +307,7 @@ tag_func_define_font_2 (SwfdecSwfDecoder * s, guint tag)
SWFDEC_DEBUG("langcode %d", langcode);
font_name_len = swfdec_bits_get_u8 (bits);
- font->name = swfdec_bits_get_string_length (bits, font_name_len);
+ font->name = swfdec_bits_get_string_length (bits, font_name_len, s->version);
if (font->name == NULL) {
SWFDEC_ERROR ("error reading font name");
} else {
@@ -399,7 +399,7 @@ tag_func_define_font_3 (SwfdecSwfDecoder * s, guint tag)
language = swfdec_bits_get_u8 (&s->b);
SWFDEC_LOG (" language = %u", (guint) language);
len = swfdec_bits_get_u8 (&s->b);
- font->name = swfdec_bits_get_string_length (&s->b, len);
+ font->name = swfdec_bits_get_string_length (&s->b, len, s->version);
if (font->name == NULL) {
SWFDEC_ERROR ("error reading font name");
} else {
More information about the Swfdec
mailing list