Skip to content

Crash when opening db without rowid and composite primary key #159

@lukas-w

Description

@lukas-w

Opening a db file with a table like this crashes SqliteBrowser:

CREATE TABLE table1 (
    id1,
    id2,
    PRIMARY KEY(id1, id2)
) WITHOUT ROWID;

The crash happens at sqlitetypes.cpp:391. That line fails because tab.findPk() returns -1 as it can't find a single primary key column.

Table CreateTableWalker::table()
{
    Table tab("");

    if( m_root ) //CREATE TABLE
    {
        …
        while(s != antlr::nullAST)
        {
            // Is this a 'without rowid' definiton?
            if(s->getType() != sqlite3TokenTypes::WITHOUT)
            {
                …
            } else {
                tab.setRowidColumn(tab.fields().at(tab.findPk())->name()); // <-- Line 391, Probably faulty
            }
        }
    }

    return tab;
}
0   QString::operator=(QString const&)  /usr/lib/libQtCore.so.4     0x7ffff69cf7dc  
1   setRowidColumn  sqlitetypes.h   97  0x4c1506    
2   sqlb::CreateTableWalker::table  sqlitetypes.cpp 391 0x4c1506    
3   sqlb::Table::parseSQL   sqlitetypes.cpp 156 0x4c2c6a    
4   DBBrowserDB::updateSchema   sqlitedb.cpp    998 0x4b2927    
5   MainWindow::populateStructure   MainWindow.cpp  271 0x47bc15    
6   MainWindow::fileOpen    MainWindow.cpp  231 0x4892e1    
7   MainWindow::dropEvent   MainWindow.cpp  1077    0x48a2d5    
8   QWidget::event(QEvent*) /usr/lib/libQtGui.so.4      0x7ffff734819a  
9   QMainWindow::event(QEvent*) /usr/lib/libQtGui.so.4      0x7ffff76fec03  
10  QApplicationPrivate::notify_helper(QObject*, QEvent*)   /usr/lib/libQtGui.so.4      0x7ffff72f8f0c  
11  QApplication::notify(QObject*, QEvent*) /usr/lib/libQtGui.so.4      0x7ffff7300376  
12  QCoreApplication::notifyInternal(QObject*, QEvent*) /usr/lib/libQtCore.so.4     0x7ffff6a8958d  
13  ??  /usr/lib/libQtGui.so.4      0x7ffff737e401  
14  QApplication::x11ClientMessage(QWidget*, _XEvent*, bool)    /usr/lib/libQtGui.so.4      0x7ffff736291d  
15  QApplication::x11ProcessEvent(_XEvent*) /usr/lib/libQtGui.so.4      0x7ffff736f80f  
16  ??  /usr/lib/libQtGui.so.4      0x7ffff7395f02  
17  g_main_context_dispatch /usr/lib/libglib-2.0.so.0       0x7ffff559dc7d  
18  ??  /usr/lib/libglib-2.0.so.0       0x7ffff559df68  
19  g_main_context_iteration    /usr/lib/libglib-2.0.so.0       0x7ffff559e01c  
20  QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)  /usr/lib/libQtCore.so.4     0x7ffff6ab62a5              

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed bugs or reports that are very likely to be bugs.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions