tulir / gomuks

A terminal based Matrix client written in Go.
https://maunium.net/go/gomuks
GNU Affero General Public License v3.0
1.34k stars 120 forks source link

gomuks crashes when exporting encryption keys #385

Open Merivuokko opened 1 year ago

Merivuokko commented 1 year ago

gomuks crashes when /export'ing encryption keys

When I run /export keys.txt

I get a fatal error and the following stack trace:

runtime error: index out of range [0] with length 0
goroutine 1934 [running]:
runtime/debug.Stack()
    /usr/lib/go/src/runtime/debug/stack.go:24 +0x65
maunium.net/go/gomuks/debug.PrettyPanic({0xfe4c20, 0xc001c82e70})
    debug/debug.go:133 +0x19a
maunium.net/go/gomuks/debug.Recover()
    debug/debug.go:107 +0x5a
panic({0xfe4c20, 0xc001c82e70})
    /usr/lib/go/src/runtime/panic.go:884 +0x212
maunium.net/go/mautrix/crypto/olm.(*InboundGroupSession).Unpickle.func1(0xc00160c000?, 0x130?, 0xc00160c000?)
    /home/aura/go/pkg/mod/maunium.net/go/mautrix@v0.11.1-0.20220518174602-87d2cd49a4d1/crypto/olm/inboundgroupsession.go:139 +0x134
maunium.net/go/mautrix/crypto/olm.(*InboundGroupSession).Unpickle(0xc000bca180?, {0x0, 0x0, 0x0}, {0xc0004be4e0, 0xd, 0xd})
    /home/aura/go/pkg/mod/maunium.net/go/mautrix@v0.11.1-0.20220518174602-87d2cd49a4d1/crypto/olm/inboundgroupsession.go:140 +0x4f
maunium.net/go/mautrix/crypto.(*SQLCryptoStore).scanGroupSessionList(0xc0004da2d0, 0x1283b50?)
    /home/aura/go/pkg/mod/maunium.net/go/mautrix@v0.11.1-0.20220518174602-87d2cd49a4d1/crypto/sql_store.go:320 +0x2ad
maunium.net/go/mautrix/crypto.(*SQLCryptoStore).GetAllGroupSessions(0xc0004da2d0)
    /home/aura/go/pkg/mod/maunium.net/go/mautrix@v0.11.1-0.20220518174602-87d2cd49a4d1/crypto/sql_store.go:361 +0xf1
maunium.net/go/gomuks/ui.cmdExportKeys(0xc000f16fa0)
    ui/crypto-commands.go:352 +0x48
maunium.net/go/gomuks/ui.(*CommandProcessor).HandleCommand(0xc00008df40, 0xc000f16fa0)
    ui/command-processor.go:279 +0xe2
created by maunium.net/go/gomuks/ui.(*RoomView).InputSubmit
    ui/room-view.go:701 +0xca

I tried to upgrade mautrix to fix this for no avail.

I don't really need to get this fixed. I just want to get all my encryption keys from gomuks. So if there is a workaround available, I'd like to hear.

jbmorley commented 9 months ago

I'm seeing a crash on key export too. Looks like a different stack trace though:

unexpected length 995608 / 999424 / 995608
goroutine 1967 [running]:
runtime/debug.Stack()
        runtime/debug/stack.go:24 +0x65
maunium.net/go/gomuks/debug.PrettyPanic({0xe8cee0, 0xc0056ccc10})
        maunium.net/go/gomuks/debug/debug.go:161 +0x19a
maunium.net/go/gomuks/debug.Recover()
        maunium.net/go/gomuks/debug/debug.go:135 +0x5a
panic({0xe8cee0, 0xc0056ccc10})
        runtime/panic.go:884 +0x212
maunium.net/go/mautrix/crypto.formatKeyExportData({0xc001214000, 0xb3ebb, 0xb3ebb})
        maunium.net/go/mautrix/crypto/keyexport.go:145 +0x33f
maunium.net/go/mautrix/crypto.ExportKeys({0xc00060ae28?, 0xf83602?}, {0xc0002bb800, 0x597, 0x700})
        maunium.net/go/mautrix/crypto/keyexport.go:188 +0x2cf
maunium.net/go/gomuks/ui.exportKeys(0xc0002b4780, {0xc0002bb800, 0x597, 0x700})
        maunium.net/go/gomuks/ui/crypto-commands.go:338 +0x116
maunium.net/go/gomuks/ui.cmdExportKeys(0xc0002b4780)
        maunium.net/go/gomuks/ui/crypto-commands.go:357 +0xa5
maunium.net/go/gomuks/ui.(*CommandProcessor).HandleCommand(0xc000440140, 0xc0002b4780)
        maunium.net/go/gomuks/ui/command-processor.go:279 +0xe2
created by maunium.net/go/gomuks/ui.(*RoomView).InputSubmit
        maunium.net/go/gomuks/ui/room-view.go:701 +0xca
nacorid commented 4 months ago

Same issue on my end. First I got this stacktrace:

runtime error: index out of range [0] with length 0
goroutine 717 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:24 +0x5e
maunium.net/go/gomuks/debug.PrettyPanic({0xf406c0, 0xc003ab7908})
        /home/nacorid/gitSources/gomuks/debug/debug.go:161 +0x191
maunium.net/go/gomuks/debug.Recover()
        /home/nacorid/gitSources/gomuks/debug/debug.go:135 +0x50
panic({0xf406c0?, 0xc003ab7908?})
        /usr/local/go/src/runtime/panic.go:770 +0x132
maunium.net/go/mautrix/crypto/olm.(*InboundGroupSession).Unpickle.func1(0x130?, 0xc0003eb2c0?, 0x130?)
        /home/nacorid/go/pkg/mod/maunium.net/go/mautrix@v0.11.1/crypto/olm/inboundgroupsession.go:139 +0x165
maunium.net/go/mautrix/crypto/olm.(*InboundGroupSession).Unpickle(0xc009d94360, {0x0, 0x0, 0x0}, {0xc00024c220, 0xd, 0xd})
        /home/nacorid/go/pkg/mod/maunium.net/go/mautrix@v0.11.1/crypto/olm/inboundgroupsession.go:140 +0x49
maunium.net/go/mautrix/crypto.(*SQLCryptoStore).scanGroupSessionList(0xc0000cc6c0, 0xc008a4def0)
        /home/nacorid/go/pkg/mod/maunium.net/go/mautrix@v0.11.1/crypto/sql_store.go:320 +0x28c
maunium.net/go/mautrix/crypto.(*SQLCryptoStore).GetAllGroupSessions(0xc0000cc6c0)
        /home/nacorid/go/pkg/mod/maunium.net/go/mautrix@v0.11.1/crypto/sql_store.go:361 +0xe8
maunium.net/go/gomuks/ui.cmdExportKeys(0xc0000fb400)
        /home/nacorid/gitSources/gomuks/ui/crypto-commands.go:352 +0x42
maunium.net/go/gomuks/ui.(*CommandProcessor).HandleCommand(0xc0000a22d0, 0xc0000fb400)
        /home/nacorid/gitSources/gomuks/ui/command-processor.go:286 +0xcb
created by maunium.net/go/gomuks/ui.(*RoomView).InputSubmit in goroutine 1
        /home/nacorid/gitSources/gomuks/ui/room-view.go:701 +0xc5

In #gomuks:matrix.org @tulir mentioned this:

it might start working if you run DELETE FROM crypto_megolm_inbound_session WHERE session IS NULL; in ~/.local/share/gomuks/crypto.db

Which I tried, after which I got this:

unexpected length 1765502 / 1769472 / 1765502
goroutine 308 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:24 +0x5e
maunium.net/go/gomuks/debug.PrettyPanic({0xec9520, 0xc001706160})
        /home/nacorid/gitSources/gomuks/debug/debug.go:161 +0x191
maunium.net/go/gomuks/debug.Recover()
        /home/nacorid/gitSources/gomuks/debug/debug.go:135 +0x50
panic({0xec9520?, 0xc001706160?})
        /usr/local/go/src/runtime/panic.go:770 +0x132
maunium.net/go/mautrix/crypto.formatKeyExportData({0xc00cb9c000, 0x13f0fe, 0x13f0fe})
        /home/nacorid/go/pkg/mod/maunium.net/go/mautrix@v0.11.1/crypto/keyexport.go:145 +0x365
maunium.net/go/mautrix/crypto.ExportKeys({0xc008887100?, 0xfa900b?}, {0xc008698008, 0x9de, 0xbff})
        /home/nacorid/go/pkg/mod/maunium.net/go/mautrix@v0.11.1/crypto/keyexport.go:188 +0x2d3
maunium.net/go/gomuks/ui.exportKeys(0xc00079c500, {0xc008698008, 0x9de, 0xbff})
        /home/nacorid/gitSources/gomuks/ui/crypto-commands.go:338 +0x10f
maunium.net/go/gomuks/ui.cmdExportKeys(0xc00079c500)
        /home/nacorid/gitSources/gomuks/ui/crypto-commands.go:357 +0x9e
maunium.net/go/gomuks/ui.(*CommandProcessor).HandleCommand(0xc0000a2c30, 0xc00079c500)
        /home/nacorid/gitSources/gomuks/ui/command-processor.go:286 +0xcb
created by maunium.net/go/gomuks/ui.(*RoomView).InputSubmit in goroutine 1
        /home/nacorid/gitSources/gomuks/ui/room-view.go:701 +0xc5
taaigo commented 3 months ago

Same problem for me, here is my stack trace

unexpected length 27823 / 28672 / 27823
goroutine 137 [running]:
runtime/debug.Stack()
    /usr/lib/go/src/runtime/debug/stack.go:24 +0x5e
maunium.net/go/gomuks/debug.PrettyPanic({0x5571e679b9e0, 0xc002752340})
    /var/tmp/portage/net-im/gomuks-0.3.0/work/gomuks-09a927955810f6f0c6d3f4809d9b01eda365fd39/debug/debug.go:161 +0x191
maunium.net/go/gomuks/debug.Recover()
    /var/tmp/portage/net-im/gomuks-0.3.0/work/gomuks-09a927955810f6f0c6d3f4809d9b01eda365fd39/debug/debug.go:135 +0x50
panic({0x5571e679b9e0?, 0xc002752340?})
    /usr/lib/go/src/runtime/panic.go:770 +0x132
maunium.net/go/mautrix/crypto.formatKeyExportData({0xc00278a000, 0x503f, 0x503f})
    /var/tmp/portage/net-im/gomuks-0.3.0/work/go-mod/maunium.net/go/mautrix@v0.11.1/crypto/keyexport.go:145 +0x365
maunium.net/go/mautrix/crypto.ExportKeys({0xc0026c7090?, 0x5571e64cc75b?}, {0xc002494200, 0x28, 0x40})
    /var/tmp/portage/net-im/gomuks-0.3.0/work/go-mod/maunium.net/go/mautrix@v0.11.1/crypto/keyexport.go:188 +0x2d3
maunium.net/go/gomuks/ui.exportKeys(0xc00010e5a0, {0xc002494200, 0x28, 0x40})
    /var/tmp/portage/net-im/gomuks-0.3.0/work/gomuks-09a927955810f6f0c6d3f4809d9b01eda365fd39/ui/crypto-commands.go:338 +0x10f
maunium.net/go/gomuks/ui.cmdExportKeys(0xc00010e5a0)
    /var/tmp/portage/net-im/gomuks-0.3.0/work/gomuks-09a927955810f6f0c6d3f4809d9b01eda365fd39/ui/crypto-commands.go:357 +0x9e
maunium.net/go/gomuks/ui.(*CommandProcessor).HandleCommand(0xc0001380f0, 0xc00010e5a0)
    /var/tmp/portage/net-im/gomuks-0.3.0/work/gomuks-09a927955810f6f0c6d3f4809d9b01eda365fd39/ui/command-processor.go:286 +0xcb
created by maunium.net/go/gomuks/ui.(*RoomView).InputSubmit in goroutine 1
    /var/tmp/portage/net-im/gomuks-0.3.0/work/gomuks-09a927955810f6f0c6d3f4809d9b01eda365fd39/ui/room-view.go
r3sist-uniq commented 5 days ago

still cannot export the keys