win32 interface: take extra precaution to prevent range check errors if the LCL attempts to put an invalid UTF8 string on the clipboard (bug #11609)

git-svn-id: trunk@15685 -
This commit is contained in:
vincents 2008-07-06 19:53:34 +00:00
parent 5f15a64ce4
commit 899a6b0d07

View File

@ -630,21 +630,27 @@ function TWin32WidgetSet.ClipboardGetOwnerShip(ClipboardType: TClipboardType;
// CF_UNICODETEXT is used by UnicodeEnabledOS, CF_TEXT by others // CF_UNICODETEXT is used by UnicodeEnabledOS, CF_TEXT by others
// we need to convert it from UTF8 to UTF16 or Ansi // we need to convert it from UTF8 to UTF16 or Ansi
begin begin
if DataStream.Size>0 then begin
SetLength(BufferString, DataStream.Size); SetLength(BufferString, DataStream.Size);
DataStream.Read(BufferString[1], DataStream.Size); DataStream.Read(BufferString[1], DataStream.Size);
if FormatID=Windows.CF_UNICODETEXT then if FormatID=Windows.CF_UNICODETEXT then
begin begin
BufferWideString := Utf8Decode(BufferString); BufferWideString := Utf8Decode(BufferString);
if BufferWideString<>'' then // bufferstring may contain invalid UTF8
BufferStream.Write(BufferWideString[1], Length(BufferWideString) * 2); BufferStream.Write(BufferWideString[1], Length(BufferWideString) * 2);
end end
else else
begin begin
BufferString := Utf8ToAnsi(BufferString); BufferString := Utf8ToAnsi(BufferString);
if BufferString<>'' then // original string may contain invalid UTF8
BufferStream.Write(BufferString[1], Length(BufferString)); BufferStream.Write(BufferString[1], Length(BufferString));
end; end;
BufferStream.Position := 0; BufferStream.Position := 0;
end;
WriteStreamToClipBoard(FormatID, BufferStream); WriteStreamToClipBoard(FormatID, BufferStream);
end end
{$ELSE}
// no clipboard support without unicode anymore
{$ENDIF} {$ENDIF}
else else
begin begin