Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-05

Clipboard.HasFormat(CF_TEXT)

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

C Western

I may have discovered an issue with the clipboard on Linux/GTK2. My application updates a paste button and menu item via an action that updates on idle by calling Clipboard.HasFormat(CF_TEXT). Pasting is intermittently failing/hanging for 10 seconds, and I think the issue is that the Clipboard.HasFormat routine is reentered. Clipboard.HasFormat can call Application.ProcessMessages, and a possible failure path seems to be that a Ctrl+V arrives during this call of ProcessMessages, and in handling this Clipboard.HasFormat is called, and the routine seems to have nothing to protect against reentry.

Two Ctrl+V's in quick succession could potentially trigger then same issue, if the clipboard contents are large.

Have I misunderstood something? I couldn't see anything in the bug tracker about this, though there is a reported issue about large pastes. I can't see any obvious fix at the application level other than leaving the paste items permanently enabled.

I think this is not an issue in MS Windows as I don't think the clipboard requires communication with another process.

Colin

Reply by email

Mattias Gaertner
to C Western
Show quoted text 20 lines
I may have discovered an issue with the clipboard on Linux/GTK2. My application updates a paste button and menu item via an action that updates on idle by calling Clipboard.HasFormat(CF_TEXT). Pasting is intermittently failing/hanging for 10 seconds, and I think the issue is that the Clipboard.HasFormat routine is reentered. Clipboard.HasFormat can call Application.ProcessMessages, and a possible failure path seems to be that a Ctrl+V arrives during this call of ProcessMessages, and in handling this Clipboard.HasFormat is called, and the routine seems to have nothing to protect against reentry. Two Ctrl+V's in quick succession could potentially trigger then same issue, if the clipboard contents are large. Have I misunderstood something? I couldn't see anything in the bug tracker about this, though there is a reported issue about large pastes. I can't see any obvious fix at the application level other than leaving the paste items permanently enabled. I think this is not an issue in MS Windows as I don't think the clipboard requires communication with another process.

Can you create a small example?

Mattias

Reply by email

C Western
to Mattias Gaertner
Mattias Gaertner wrote 26 lines
On Mon, 26 May 2014 12:31:41 +0100 C Western wrote: > I may have discovered an issue with the clipboard on Linux/GTK2. My > application updates a paste button and menu item via an action that > updates on idle by calling Clipboard.HasFormat(CF_TEXT). Pasting is > intermittently failing/hanging for 10 seconds, and I think the issue is > that the Clipboard.HasFormat routine is reentered. Clipboard.HasFormat > can call Application.ProcessMessages, and a possible failure path seems > to be that a Ctrl+V arrives during this call of ProcessMessages, and in > handling this Clipboard.HasFormat is called, and the routine seems to > have nothing to protect against reentry. > > Two Ctrl+V's in quick succession could potentially trigger then same > issue, if the clipboard contents are large. > > Have I misunderstood something? I couldn't see anything in the bug > tracker about this, though there is a reported issue about large pastes. > I can't see any obvious fix at the application level other than leaving > the paste items permanently enabled. > > I think this is not an issue in MS Windows as I don't think the > clipboard requires communication with another process. Can you create a small example?

I would think that any application that uses the clipboard would be vulnerable to this. For example, I think I can trigger the issue with two Ctrl-V's in succession with the edittest example in lazarus. Start it and say libre office (I used a spreadsheet with about 1000 lines of data.) Select and copy a large block in the spreadsheet, and then hold down the Ctrl+v key in edittest. A few copies will appear very quickly, but then the application hangs for several seconds (at least). Lazarus itself can be made to hang in the same way.

Colin

Reply by email

Mattias Gaertner
to C Western
Show quoted text 9 lines
[...] I would think that any application that uses the clipboard would be vulnerable to this. For example, I think I can trigger the issue with two Ctrl-V's in succession with the edittest example in lazarus. Start it and say libre office (I used a spreadsheet with about 1000 lines of data.) Select and copy a large block in the spreadsheet, and then hold down the Ctrl+v key in edittest. A few copies will appear very quickly, but then the application hangs for several seconds (at least). Lazarus itself can be made to hang in the same way.

Do you mean the copies could be processed in the wrong order?

Mattias

Reply by email

Colin Western
to Mattias Gaertner

In the wrong order is certainly a possibility also, though I was more concerned about the hang. When the actions overlap, I think anything can happen.

Mattias Gaertner wrote 28 lines
On Mon, 26 May 2014 18:16:10 +0100 C Western wrote: >[...] > I would think that any application that uses the clipboard would be > vulnerable to this. For example, I think I can trigger the issue with > two Ctrl-V's in succession with the edittest example in lazarus. Start > it and say libre office (I used a spreadsheet with about 1000 lines of > data.) Select and copy a large block in the spreadsheet, and then hold > down the Ctrl+v key in edittest. A few copies will appear very quickly, > but then the application hangs for several seconds (at least). Lazarus > itself can be made to hang in the same way. Do you mean the copies could be processed in the wrong order? Mattias -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140526/2f5cf6ce/attachment.html>

Reply by email

C Western
to Colin Western
Colin Western wrote 31 lines
In the wrong order is certainly a possibility also, though I was more concerned about the hang. When the actions overlap, I think anything can happen. On 26 May 2014 18:43:23 BST, Mattias Gaertner wrote: On Mon, 26 May 2014 18:16:10 +0100 C Western wrote: [...] I would think that any application that uses the clipboard would be vulnerable to this. For example, I think I can trigger the issue with two Ctrl-V's in succession with the edittest example in lazarus. Start it and say libre office (I used a spreadsheet with about 1000 lines of data.) Select and copy a large block in the spreadsheet, and then hold down the Ctrl+v key in edittest. A few copies will appear very quickly, but then the application hangs for several seconds (at least). Lazarus itself can be made to hang in the same way. Do you mean the copies could be processed in the wrong order? Mattias

I have done some more investigation of this, and come up with a possible patch
http://bugs.freepascal.org/view.php?id=26242

Colin

Reply by email