- else {
- gchar* svg_open_end = g_strstr_len(svg_open_start, decoded_size, ">");
- if (svg_open_end == NULL) {
- /* The decoded data is not what we were expecting. Give up. */
- g_free(decoded);
- return NULL;
- }
- memset(decoded, ' ', (1 + (svg_open_end - decoded)));
+
+ gchar* svg_open_end = g_strstr_len(svg_open_start,
+ (decoded+decoded_size) - svg_open_start,
+ ">");
+ if (svg_open_end == NULL) {
+ /* The decoded data is not what we were expecting. Give up. */
+ g_free(decoded);
+ return NULL;
+ }
+
+ /* Keep in mind that we want to wipe everything up to and
+ including the <svg> tag; we'll usually overwrite an <xml> tag
+ too. */
+ memset(decoded, ' ', (1 + (svg_open_end - decoded)));
+
+ gchar* svg_close_start = g_strstr_len(svg_open_end,
+ (decoded+decoded_size)-svg_open_end,
+ "</svg>");
+ if (svg_close_start == NULL ) {
+ /* The decoded data is not what we were expecting. Give up. */
+ g_free(decoded);
+ return NULL;