mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
id3v2: fix splitting strings in ISO-8859-1 and UTF-16 formats
When parsing NUL-terminated strings, do not include the terminating NUL byte(s). Depending on the encoding used, either g_utf8_validate() failed due to this, or worse the call to g_utf16_to_utf8() would return 0 items read on an empty string, causing it to fail parsing certain frames. https://bugzilla.gnome.org/show_bug.cgi?id=770355
This commit is contained in:
parent
da6070054f
commit
cd101ce8f0
1 changed files with 10 additions and 7 deletions
|
@ -1103,11 +1103,16 @@ parse_insert_string_field (guint8 encoding, gchar * data, gint data_size,
|
||||||
/* Sometimes we see strings with multiple BOM markers at the start.
|
/* Sometimes we see strings with multiple BOM markers at the start.
|
||||||
* In that case, we assume the innermost one is correct. If that fails
|
* In that case, we assume the innermost one is correct. If that fails
|
||||||
* to produce valid UTF-8, we try the other endianness anyway */
|
* to produce valid UTF-8, we try the other endianness anyway */
|
||||||
while (data_size > 2 && find_utf16_bom (data, &data_endianness)) {
|
while (data_size >= 2 && find_utf16_bom (data, &data_endianness)) {
|
||||||
data += 2; /* skip BOM */
|
data += 2; /* skip BOM */
|
||||||
data_size -= 2;
|
data_size -= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data_size < 2) {
|
||||||
|
field = g_strdup ("");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* alloc needed to ensure correct alignment which is required by GLib */
|
/* alloc needed to ensure correct alignment which is required by GLib */
|
||||||
len = data_size / 2;
|
len = data_size / 2;
|
||||||
utf16 = g_try_new (gunichar2, len + 1);
|
utf16 = g_try_new (gunichar2, len + 1);
|
||||||
|
@ -1193,7 +1198,7 @@ parse_split_strings (guint8 encoding, gchar * data, gint data_size,
|
||||||
for (text_pos = 0; text_pos < data_size; text_pos++) {
|
for (text_pos = 0; text_pos < data_size; text_pos++) {
|
||||||
if (data[text_pos] == 0) {
|
if (data[text_pos] == 0) {
|
||||||
parse_insert_string_field (encoding, data + prev,
|
parse_insert_string_field (encoding, data + prev,
|
||||||
text_pos - prev + 1, fields);
|
text_pos - prev, fields);
|
||||||
prev = text_pos + 1;
|
prev = text_pos + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1207,7 +1212,7 @@ parse_split_strings (guint8 encoding, gchar * data, gint data_size,
|
||||||
for (prev = 0, text_pos = 0; text_pos < data_size; text_pos++) {
|
for (prev = 0, text_pos = 0; text_pos < data_size; text_pos++) {
|
||||||
if (data[text_pos] == '\0') {
|
if (data[text_pos] == '\0') {
|
||||||
parse_insert_string_field (encoding, data + prev,
|
parse_insert_string_field (encoding, data + prev,
|
||||||
text_pos - prev + 1, fields);
|
text_pos - prev, fields);
|
||||||
prev = text_pos + 1;
|
prev = text_pos + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1224,10 +1229,8 @@ parse_split_strings (guint8 encoding, gchar * data, gint data_size,
|
||||||
if (data[text_pos] == '\0' && data[text_pos + 1] == '\0') {
|
if (data[text_pos] == '\0' && data[text_pos + 1] == '\0') {
|
||||||
/* found a delimiter */
|
/* found a delimiter */
|
||||||
parse_insert_string_field (encoding, data + prev,
|
parse_insert_string_field (encoding, data + prev,
|
||||||
text_pos - prev + 2, fields);
|
text_pos - prev, fields);
|
||||||
text_pos++; /* Advance to the 2nd NULL terminator */
|
prev = text_pos + 2;
|
||||||
prev = text_pos + 1;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data_size - prev > 1 &&
|
if (data_size - prev > 1 &&
|
||||||
|
|
Loading…
Reference in a new issue