Pekka Lampila
2007-Oct-31 12:57 UTC
[Swfdec] 2 commits - libswfdec/swfdec_sound.c libswfdec/swfdec_text_field_movie_as.c libswfdec/swfdec_text_field_movie.c libswfdec/swfdec_text_field_movie_html.c
libswfdec/swfdec_sound.c | 5 ++++- libswfdec/swfdec_text_field_movie.c | 24 +++++++++--------------- libswfdec/swfdec_text_field_movie_as.c | 19 +++++++++++++++---- libswfdec/swfdec_text_field_movie_html.c | 6 +++--- 4 files changed, 31 insertions(+), 23 deletions(-) New commits: commit 73aaa5c30a072ebf5be478d943526450aedb312c Author: Pekka Lampila <pekka.lampila at iki.fi> Date: Wed Oct 31 14:54:09 2007 +0200 Always use byte offsets internally in TextField, not UTF-8 offsets Fixes at least one assert diff --git a/libswfdec/swfdec_text_field_movie.c b/libswfdec/swfdec_text_field_movie.c index dc2cca0..1858004 100644 --- a/libswfdec/swfdec_text_field_movie.c +++ b/libswfdec/swfdec_text_field_movie.c @@ -1033,7 +1033,7 @@ swfdec_text_field_movie_set_text_format (SwfdecTextFieldMovie *text, g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text)); g_return_if_fail (SWFDEC_IS_TEXT_FORMAT (format)); g_return_if_fail (start_index < end_index); - g_return_if_fail (end_index <= (guint) g_utf8_strlen (text->input->str, -1)); + g_return_if_fail (end_index <= text->input->len); g_assert (text->formats != NULL); g_assert (text->formats->data != NULL); @@ -1051,7 +1051,7 @@ swfdec_text_field_movie_set_text_format (SwfdecTextFieldMovie *text, findex_end_index ((SwfdecFormatIndex *)iter->next->data)->index_; } else { - findex_end_index = g_utf8_strlen (text->input->str, -1); + findex_end_index = text->input->len; } if (findex_end_index <= start_index) @@ -1113,7 +1113,7 @@ swfdec_text_field_movie_get_text_format (SwfdecTextFieldMovie *text, g_assert (SWFDEC_IS_TEXT_FIELD_MOVIE (text)); g_assert (start_index < end_index); - g_assert (end_index <= (guint) g_utf8_strlen (text->input->str, -1)); + g_assert (end_index <= text->input->len); g_assert (text->formats != NULL); g_assert (text->formats->data != NULL); @@ -1288,7 +1288,7 @@ swfdec_text_field_movie_replace_text (SwfdecTextFieldMovie *text, gboolean first; g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text)); - g_return_if_fail (end_index <= (guint) g_utf8_strlen (text->input->str, -1)); + g_return_if_fail (end_index <= text->input->len); g_return_if_fail (start_index <= end_index); g_return_if_fail (str != NULL); @@ -1304,8 +1304,7 @@ swfdec_text_field_movie_replace_text (SwfdecTextFieldMovie *text, findex = iter->data; if (findex->index_ >= start_index) { - if (end_index == (guint) g_utf8_strlen (text->input->str, -1) || - (iter->next != NULL && + if (end_index == text->input->len ||(iter->next != NULL && ((SwfdecFormatIndex *)iter->next->data)->index_ <= end_index)) { g_free (iter->data); @@ -1324,7 +1323,7 @@ swfdec_text_field_movie_replace_text (SwfdecTextFieldMovie *text, prev = iter; } - if (end_index == (guint) g_utf8_strlen (text->input->str, -1)) { + if (end_index == text->input->len) { if (SWFDEC_AS_OBJECT (text)->context->version < 8) { SWFDEC_FIXME ("replaceText to the end of the TextField might use wrong text format on version 7"); } @@ -1335,14 +1334,9 @@ swfdec_text_field_movie_replace_text (SwfdecTextFieldMovie *text, text->formats = g_slist_append (text->formats, findex); } - text->input = g_string_erase (text->input, - g_utf8_offset_to_pointer (text->input->str, start_index) - - text->input->str, - g_utf8_offset_to_pointer (text->input->str, end_index) - - g_utf8_offset_to_pointer (text->input->str, start_index)); - text->input = g_string_insert (text->input, - g_utf8_offset_to_pointer (text->input->str, start_index) - - text->input->str, str); + text->input = g_string_erase (text->input, start_index, + end_index - start_index); + text->input = g_string_insert (text->input, start_index, str); swfdec_movie_invalidate (SWFDEC_MOVIE (text)); swfdec_text_field_movie_auto_size (text); diff --git a/libswfdec/swfdec_text_field_movie_as.c b/libswfdec/swfdec_text_field_movie_as.c index 248d878..7d91250 100644 --- a/libswfdec/swfdec_text_field_movie_as.c +++ b/libswfdec/swfdec_text_field_movie_as.c @@ -1031,7 +1031,11 @@ swfdec_text_field_movie_setTextFormat (SwfdecAsContext *cx, format = SWFDEC_TEXT_FORMAT (SWFDEC_AS_VALUE_GET_OBJECT (&argv[i])); - swfdec_text_field_movie_set_text_format (text, format, start_index, end_index); + swfdec_text_field_movie_set_text_format (text, format, + g_utf8_offset_to_pointer (text->input->str, start_index) - + text->input->str, + g_utf8_offset_to_pointer (text->input->str, end_index) - + text->input->str); } SWFDEC_AS_NATIVE (104, 101, swfdec_text_field_movie_getTextFormat) @@ -1068,8 +1072,11 @@ swfdec_text_field_movie_getTextFormat (SwfdecAsContext *cx, if (start_index == end_index) { format = SWFDEC_TEXT_FORMAT (swfdec_text_format_new (cx)); } else { - format - swfdec_text_field_movie_get_text_format (text, start_index, end_index); + format = swfdec_text_field_movie_get_text_format (text, + g_utf8_offset_to_pointer (text->input->str, start_index) - + text->input->str, + g_utf8_offset_to_pointer (text->input->str, end_index) - + text->input->str); } SWFDEC_AS_VALUE_SET_OBJECT (ret, SWFDEC_AS_OBJECT (format)); @@ -1097,7 +1104,11 @@ swfdec_text_field_movie_replaceText (SwfdecAsContext *cx, start_index = MIN (start_index, g_utf8_strlen (text->input->str, -1)); end_index = MIN (end_index, g_utf8_strlen (text->input->str, -1)); - swfdec_text_field_movie_replace_text (text, start_index, end_index, str); + swfdec_text_field_movie_replace_text (text, + g_utf8_offset_to_pointer (text->input->str, start_index) - + text->input->str, + g_utf8_offset_to_pointer (text->input->str, end_index) - + text->input->str, str); } // static diff --git a/libswfdec/swfdec_text_field_movie_html.c b/libswfdec/swfdec_text_field_movie_html.c index 3352bd6..ef22415 100644 --- a/libswfdec/swfdec_text_field_movie_html.c +++ b/libswfdec/swfdec_text_field_movie_html.c @@ -71,7 +71,7 @@ swfdec_text_field_movie_html_parse_close_tag (ParserData *data, ParserTag *tag) ParserTag *n = g_new0 (ParserTag, 1); n->name = f->name; n->name_length = f->name_length; - n->index = g_utf8_strlen (data->text->str, -1); + n->index = data->text->len; n->end_index = n->index + 1; n->format = swfdec_text_format_copy (f->format); data->tags_closed = g_slist_prepend (data->tags_closed, n); @@ -81,7 +81,7 @@ swfdec_text_field_movie_html_parse_close_tag (ParserData *data, ParserTag *tag) data->text = g_string_append_c (data->text, '\n'); } - tag->end_index = g_utf8_strlen (data->text->str, -1); + tag->end_index = data->text->len; data->tags_open = g_slist_remove (data->tags_open, tag); data->tags_closed = g_slist_prepend (data->tags_closed, tag); @@ -347,7 +347,7 @@ swfdec_text_field_movie_html_parse_tag (ParserData *data, const char *p) tag->name = name; tag->name_length = name_length; tag->format = SWFDEC_TEXT_FORMAT (swfdec_text_format_new (data->cx)); - tag->index = g_utf8_strlen (data->text->str, -1); + tag->index = data->text->len; data->tags_open = g_slist_prepend (data->tags_open, tag); commit a69bc92b48bb2fd9fd32e1d0d7f6fd477e1c4a98 Author: Pekka Lampila <pekka.lampila at iki.fi> Date: Wed Oct 31 12:24:31 2007 +0200 Handle running out of bits in sound envelope parsing better diff --git a/libswfdec/swfdec_sound.c b/libswfdec/swfdec_sound.c index 3e9da94..06022bc 100644 --- a/libswfdec/swfdec_sound.c +++ b/libswfdec/swfdec_sound.c @@ -356,7 +356,7 @@ swfdec_sound_parse_chunk (SwfdecSwfDecoder *s, SwfdecBits *b, int id) SWFDEC_LOG (" n_envelopes = %u", chunk->n_envelopes); } - for (i = 0; i < chunk->n_envelopes; i++) { + for (i = 0; i < chunk->n_envelopes && swfdec_bits_left (b); i++) { chunk->envelope[i].offset = swfdec_bits_get_u32 (b); if (i > 0 && chunk->envelope[i-1].offset > chunk->envelope[i].offset) { SWFDEC_ERROR ("unordered sound envelopes"); @@ -376,6 +376,9 @@ swfdec_sound_parse_chunk (SwfdecSwfDecoder *s, SwfdecBits *b, int id) (guint) chunk->envelope[i].volume[0], (guint) chunk->envelope[i].volume[1]); } + if (i < chunk->n_envelopes) + SWFDEC_ERROR ("out of bits when reading sound envelopes"); + return chunk; }
Apparently Analagous Threads
- 5 commits - libswfdec/swfdec_html_parser.c libswfdec/swfdec_text_field_movie_as.c libswfdec/swfdec_text_field_movie.c test/trace
- 12 commits - libswfdec/swfdec_as_internal.h libswfdec/swfdec_as_interpret.c libswfdec/swfdec_as_object.c libswfdec/swfdec_text_field_movie_as.c libswfdec/swfdec_text_field_movie.c test/trace
- libswfdec/swfdec_text_field_movie.c libswfdec/swfdec_text_field_movie_html.c
- 20 commits - libswfdec/Makefile.am libswfdec/swfdec_as_interpret.c libswfdec/swfdec_html_parser.c libswfdec/swfdec_initialize.as libswfdec/swfdec_initialize.h libswfdec/swfdec_text_field.c libswfdec/swfdec_text_field.h
- 12 commits - libswfdec/swfdec_as_strings.c libswfdec/swfdec_html_parser.c libswfdec/swfdec_text_field.c libswfdec/swfdec_text_field.h libswfdec/swfdec_text_field_movie_as.c libswfdec/swfdec_text_field_movie.c libswfdec/swfdec_text_field_movie.h test/trace