Fix #4265: "Segfault saving image with edited metadata"

This commit is contained in:
Hombre
2017-12-31 00:48:33 +01:00
parent 5ecb05ba23
commit 32d0a934f4

View File

@@ -1938,17 +1938,15 @@ void Tag::initUserComment (const Glib::ustring &text)
count = 8 + strlen (text.c_str()); count = 8 + strlen (text.c_str());
valuesize = count; valuesize = count;
value = new unsigned char[valuesize]; value = new unsigned char[valuesize];
strcpy ((char*)value, "ASCII"); memcpy((char*)value, "ASCII\0\0\0", 8);
value[5] = value[6] = value[7] = 0; memcpy((char*)value + 8, text.c_str(), valuesize - 8);
strcpy ((char*)value + 8, text.c_str());
} else { } else {
wchar_t *commentStr = (wchar_t*)g_utf8_to_utf16 (text.c_str(), -1, NULL, NULL, NULL); wchar_t *commentStr = (wchar_t*)g_utf8_to_utf16 (text.c_str(), -1, NULL, NULL, NULL);
count = 8 + wcslen(commentStr)*2; count = 8 + wcslen(commentStr)*2;
valuesize = count; valuesize = count;
value = (unsigned char*)new char[valuesize]; value = (unsigned char*)new char[valuesize];
strcpy ((char*)value, "UNICODE"); memcpy((char*)value, "UNICODE\0", 8);
value[7] = 0; memcpy((char*)value + 8, (char*)commentStr, valuesize - 8);
wcscpy(((wchar_t*)value) + 4, commentStr);
g_free(commentStr); g_free(commentStr);
} }
} }