yatisht / usher

Ultrafast Sample Placement on Existing Trees
MIT License
121 stars 41 forks source link

Fix segv when get_subtree is called without keep_clade_annotations on tree with annotations #256

Closed AngieHinrichs closed 1 year ago

AngieHinrichs commented 1 year ago

@mdperry and I independently found a SEGV condition when switching to the latest version of usher/matUtils: when MAT::get_subtree is called without keep_clade_annotations=true, and the tree contains clade annotations, get_subtree creates new nodes with clade_annotations size 0 but then attempts to copy the existing node's clade annotations. This was an unintended side effect of 052cf4a6 (which solved a different problem that could occur when keep_clade_annotations=true is passed in).

The solution is to limit the loop that copies clade annotations into the new node to the minimum of num_annotations (which is 0 when keep_clade_annotations is false) and source node's clade_annotations.size(), so overrun of clade_annotations is prevented for both the new node and the existing node.

AngieHinrichs commented 1 year ago

The usher-optimize-dev branch will need this too.

yatisht commented 1 year ago

Perhaps it's time to merge usher-optimize-dev to master. @yceh