Skip to content

Crash in wxGtkTreeModelNode::Resort() when node has one leaf child (wxGTK 3.3.0) #25625

Description

@oblenivshiysyaa

Description

Bug description

The program crashes inside wxGtkTreeModelNode::Resort() when the node has exactly one child that is a leaf item (not another node).
In this case m_nodes is empty, but the code still calls m_nodes.front().
On GNU/Linux this throws an exception from std::vector::front() and the application aborts.

Expected vs observed behaviour

Expected: Calling Resort() should do nothing special for a single leaf or, at most, return without errors.

Observed: The application terminates with an uncaught std::out_of_range (or similar) because front() is used on an empty vector.

Stack trace

wxDataViewCtrlInternal::Resort(wxDataViewCtrlInternal * const this) 
wxGtkDataViewModelNotifier::Resort(wxGtkDataViewModelNotifier * const this)
wxDataViewModel::Resort(wxDataViewModel * const this) 
wxgtk_tree_model_set_sort_column_id(GtkTreeSortable * sortable, gint sort_column_id, GtkSortType order)

Patch or snippet allowing to reproduce the problem

The dataview sample can be used for this

To reproduce

  1. Delete all elements from dataview (in classical music or in pop music) except one
  2. Click on column header
  3. Application aborts

Quick fix

Add additional check for non-empty m_nodes to void wxGtkTreeModelNode::Resort() function in 3540 row:

if (child_count == 1)
{
    if (!m_nodes.empty())          // guard added back
        m_nodes.front()->Resort();
    return;
}

Platform and version information

  • wxWidgets version you use: 3.3.0
  • wxWidgets port you use: wxGTK
  • OS and its version: Ubuntu 22.04 and Astra Linux SE 1.8 (based on Debian 12)
    • GTK version: 3.24.33 (Ubuntu), 3.24.38 (Astra)
    • Which GDK backend is used: Wayland (Ubuntu), X11 (Astra)
    • Desktop environment : Gnome (Ubuntu), Fly (Astra)
    • Current theme: Default

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions