Fix crashes when pasting non-text data in wxOSX

Check that conversions succeed before using their results to avoid
crashing if the data on clipboard is in an unexpected format.

Closes #18344.
This commit is contained in:
Tim Kosse
2019-02-12 16:19:18 +01:00
committed by Vadim Zeitlin
parent fb00507fb5
commit dd56499fe9

View File

@@ -469,8 +469,12 @@ bool wxDataObject::GetFromPasteboard( void * pb )
{ {
// revert the translation and decomposition to arrive at a proper utf8 string again // revert the translation and decomposition to arrive at a proper utf8 string again
CFURLRef url = CFURLCreateWithBytes( kCFAllocatorDefault, CFDataGetBytePtr( flavorData ), flavorDataSize, kCFStringEncodingUTF8, NULL ); CFURLRef url = CFURLCreateWithBytes( kCFAllocatorDefault, CFDataGetBytePtr( flavorData ), flavorDataSize, kCFStringEncodingUTF8, NULL );
if ( url )
{
CFStringRef cfString = CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle ); CFStringRef cfString = CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle );
CFRelease( url ); CFRelease( url );
if ( cfString )
{
CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfString); CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfString);
CFRelease( cfString ); CFRelease( cfString );
CFStringNormalize(cfMutableString,kCFStringNormalizationFormC); CFStringNormalize(cfMutableString,kCFStringNormalizationFormC);
@@ -478,6 +482,8 @@ bool wxDataObject::GetFromPasteboard( void * pb )
if (!path.empty()) if (!path.empty())
filenamesPassed += path + wxT("\n"); filenamesPassed += path + wxT("\n");
} }
}
}
else else
{ {
// because some data implementation expect trailing a trailing NUL, we add some headroom // because some data implementation expect trailing a trailing NUL, we add some headroom