diff options
author | Matthias Clasen <mclasen@redhat.com> | 2011-12-16 16:38:41 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2011-12-16 16:41:54 -0500 |
commit | 23cdf123efacbdaa47e4d73cdc74e5a3356b18b1 (patch) | |
tree | fc31fff08549a86b813211756dc76a672df70c77 | |
parent | 74b8bfbc1e04f7de17a2e9900327ae45ef2ae2c7 (diff) | |
download | gdk-pixbuf-23cdf123efacbdaa47e4d73cdc74e5a3356b18b1.tar.gz |
Fix handling of options when saving pngs
The png loader treats its options in two passes, the first pass
counts and verifies them, the second pass converts text options.
This worked ok when only text was understood, but with the introduction
of compression and icc-profile as supported options, the two loops
can now get out of sync when the text options are not all at the
beginning.
Fix this by skipping non-text options in the second loop, just
as we do in the first loop.
https://bugzilla.gnome.org/show_bug.cgi?id=620911
-rw-r--r-- | gdk-pixbuf/io-png.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/gdk-pixbuf/io-png.c b/gdk-pixbuf/io-png.c index 76f33049b..b2032c42c 100644 --- a/gdk-pixbuf/io-png.c +++ b/gdk-pixbuf/io-png.c @@ -923,11 +923,19 @@ static gboolean real_save_png (GdkPixbuf *pixbuf, } if (num_keys > 0) { + gchar **kiter = keys; + gchar **viter = values; + text_ptr = g_new0 (png_text, num_keys); for (i = 0; i < num_keys; i++) { + if (strncmp (*kiter, "tEXt::", 6) != 0) { + kiter++; + viter++; + } + text_ptr[i].compression = PNG_TEXT_COMPRESSION_NONE; - text_ptr[i].key = keys[i] + 6; - text_ptr[i].text = g_convert (values[i], -1, + text_ptr[i].key = *kiter + 6; + text_ptr[i].text = g_convert (*viter, -1, "ISO-8859-1", "UTF-8", NULL, &text_ptr[i].text_length, NULL); @@ -935,7 +943,7 @@ static gboolean real_save_png (GdkPixbuf *pixbuf, #ifdef PNG_iTXt_SUPPORTED if (!text_ptr[i].text) { text_ptr[i].compression = PNG_ITXT_COMPRESSION_NONE; - text_ptr[i].text = g_strdup (values[i]); + text_ptr[i].text = g_strdup (*viter); text_ptr[i].text_length = 0; text_ptr[i].itxt_length = strlen (text_ptr[i].text); text_ptr[i].lang = NULL; @@ -944,16 +952,19 @@ static gboolean real_save_png (GdkPixbuf *pixbuf, #endif if (!text_ptr[i].text) { + gint j; g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_BAD_OPTION, - _("Value for PNG text chunk %s cannot be converted to ISO-8859-1 encoding."), keys[i] + 6); - num_keys = i; - for (i = 0; i < num_keys; i++) - g_free (text_ptr[i].text); + _("Value for PNG text chunk %s cannot be converted to ISO-8859-1 encoding."), *kiter + 6); + for (j = 0; j < i; j++) + g_free (text_ptr[j].text); g_free (text_ptr); return FALSE; } + + kiter++; + viter++; } } |