Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TBaseVirtualTree.InternalAddToSelection() may cause access violation #754

Closed
nminkov opened this issue Feb 5, 2018 · 4 comments
Closed
Assignees
Labels
Milestone

Comments

@nminkov
Copy link

nminkov commented Feb 5, 2018

Hello,

You have introduced changes in TBaseVirtualTree.InternalAddToSelection which cause access violations.

More specifically, FSelectionCount is incremented before node is actually added to FSelection array.
Because FOnAddToSelection event is called in between FSelectionCount increment and actual add into FSelection, if FOnAddToSelection does modify the tree selection, it will cause access violation.

E.g. If tree has 3 nodes, there is no selection, add one element to selection, then if in FOnAddToSelection changes the selection, like calling RemoveFromSelection, TBaseVirtualTree.FindNodeInSelection will crash with access violation because FSelectionCount is 1 but FSelection is nil.

I've modified this function to do the add in 4 steps.

  1. Filter the nodes to add and add their indexes to an array
  2. Add nodes to FSelection array (unmodified)
  3. Increment the FSelectionCount
  4. Postprocess the added nodes and for each, set proper state, call the FOnAddToSelection

mypatch.txt

@joachimmarder joachimmarder self-assigned this Feb 5, 2018
@joachimmarder
Copy link
Contributor

You have introduced changes in TBaseVirtualTree.InternalAddToSelection which cause access violations.

Can you name the commit or the version?

@nminkov
Copy link
Author

nminkov commented Feb 5, 2018

I was using the original VirtualTree code and your code crashed in my usage. Took me time to trace back and its commit:

Revision: 8e7e44e
Author: Joachim Marder [email protected]
Date: 04.05.2015 22:02:01
Message:
Fixed issue #487: When OnAddToSelection is called, GetFirstSelected returns nil

@joachimmarder joachimmarder changed the title TBaseVirtualTree.InternalAddToSelection serious bug TBaseVirtualTree.InternalAddToSelection() may cause access violation Feb 6, 2018
joachimmarder pushed a commit that referenced this issue Feb 6, 2018
…se access violation. Thx@nminkov for the patch.
@joachimmarder
Copy link
Contributor

I reviewed you patch and it looks good. It also does not make #487 reoccur, which is often a problem. Thanks for you contribution.

@joachimmarder joachimmarder added this to the V7.0 milestone Feb 6, 2018
@nminkov
Copy link
Author

nminkov commented Feb 6, 2018

Thanks for accepting it and maintaining the project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants