mautrix / signal

A Matrix-Signal puppeting bridge
GNU Affero General Public License v3.0
499 stars 75 forks source link

segfault while relaying message #415

Closed LukasNeuberger closed 9 months ago

LukasNeuberger commented 9 months ago

I am using the Go signal bridge (docker image 19929f6) to relay messages between Whatsapp and Signal groups. While relaying a message from a Whatsapp user to Signal I got the following segfault:

2024-01-05T19:17:54Z DBG Starting handling of transaction content={"pdu":0,"unstable_edu":3,"unstable_to_device":0} transaction_id=88262
2024-01-05T19:17:54Z DBG Finished dispatching events from transaction transaction_id=88262
2024-01-05T19:17:54Z DBG Starting handling of transaction content={"pdu":1,"unstable_edu":0,"unstable_to_device":0} transaction_id=88263
2024-01-05T19:17:54Z DBG Finished dispatching events from transaction transaction_id=88263
2024-01-05T19:17:54Z DBG Sent message checkpoint message_checkpoint={"event_id":"$5rqYhk3XQmK55VxWNH6U8bu2V8wyH7OWapuKScEwzw4","event_type":"m.room.message","message_type":"m.text","reported_by":"BRIDGE","retry_num":0,"room_id":"!dCwPCGtRSWSHIyZkmT:mydomain.dev","status":"SUCCESS","step":"BRIDGE","timestamp":1704482274300}
2024-01-05T19:17:54Z DBG Handling Matrix read receipt chat_id=avS8jAtv7iWiIFp5qK/a4DMRX9Zhi3+RLJmEtb1aEeY= event_id= explicit=false sender=@whatsapp_xxxcensoredxxx:mydomain.dev
2024-01-05T19:17:54Z DBG Updated last read timestamp of portal chat_id=avS8jAtv7iWiIFp5qK/a4DMRX9Zhi3+RLJmEtb1aEeY= event_id= explicit=false last_read_ts=1704482274000 portal_key={"ChatID":"avS8jAtv7iWiIFp5qK/a4DMRX9Zhi3+RLJmEtb1aEeY=","Receiver":"00000000-0000-0000-0000-000000000000"} sender=@whatsapp_xxxcensoredxxx:mydomain.dev user_id=@whatsapp_xxxcensoredxxx:mydomain.dev
2024-01-05T19:17:54Z DBG Collected read receipt target messages chat_id=avS8jAtv7iWiIFp5qK/a4DMRX9Zhi3+RLJmEtb1aEeY= event_id= explicit=false max_timestamp=1704482274000 min_timestamp=1704477073612 prev_last_read_ts=1704477073612 sender=@whatsapp_xxxcensoredxxx:mydomain.dev targets={"8c862590-bbe9-45eb-ae61-23b80f593d9e":[1704480687479]}
2024-01-05T19:17:54Z DBG Outgoing message: receiptMessage (message), { type (enum), timestamp (uint64), [ <>, ] }  component=signalmeow
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0xb95eef]

goroutine 237 [running]:
go.mau.fi/mautrix-signal/pkg/signalmeow.sendContent({0x17eec58, 0xc00028aaf0}, 0x0, {0x8c, 0x86, 0x25, 0x90, 0xbb, 0xe9, 0x45, ...}, ...)
    /builds/mautrix/signal/pkg/signalmeow/sending.go:640 +0x18f
go.mau.fi/mautrix-signal/pkg/signalmeow.SendMessage({0x17eec58, 0xc00028aaf0}, 0x0, {0x8c, 0x86, 0x25, 0x90, 0xbb, 0xe9, 0x45, ...}, ...)
    /builds/mautrix/signal/pkg/signalmeow/sending.go:564 +0xe7
main.(*Portal).handleMatrixReadReceipt(0xc000882270, 0xc000018840, {0x0, 0x0}, 0x18cdb0f7ad0, 0x0)
    /builds/mautrix/signal/portal.go:1300 +0xb13
main.(*Portal).handleMatrixMessage(0xc000882270, {0x17eebb0, 0xc00038e270}, 0xc000018840, 0xc000816820)
    /builds/mautrix/signal/portal.go:369 +0x20e
main.(*Portal).handleMatrixMessages(0xc000882270, {0xc000816820?, 0xc000018840?})
    /builds/mautrix/signal/portal.go:350 +0x4f6
main.(*Portal).messageLoop(0xc000882270)
    /builds/mautrix/signal/portal.go:326 +0xc5
created by main.(*SignalBridge).NewPortal in goroutine 291
    /builds/mautrix/signal/portal.go:207 +0x4c5
2024-01-05T19:17:54Z INF Initializing bridge built_at="Jan  4 2024, 18:00:33" go_version=go1.21.5 name=mautrix-signal version=0.4.99+dev.a91fc702
2024-01-05T19:17:54Z DBG Initializing database connection
2024-01-05T19:17:54Z DBG Initializing state store
2024-01-05T19:17:54Z DBG Initializing Matrix event processor
2024-01-05T19:17:54Z DBG Initializing Matrix event handler
2024-01-05T19:17:54Z INF Initializing libsignal version:0.37.0 component=libsignal file=rust/bridge/ffi/src/logging.rs line=99 target=signal_ffi::logging
2024-01-05T19:17:54Z INF Bridge initialization complete, starting...

Otherwise the Go version has worked fine for relaying so far in multiple groups. I was not able to reproduce this, is the callstack enough to pinpoint the issue?

LukasNeuberger commented 9 months ago

thanks for the quick fix!

LukasNeuberger commented 9 months ago

I am getting a different segfault with the newer version (docker image 93ca247/commit 6286fc9):

2024-01-06T08:20:36Z DBG Request completed as_user_id=@signalbot:mydomain.dev duration=30004.20388 method=GET req_id=613 response_length=210 response_mime=application/json status_code=200 url=http://synapse:8008/_matrix/client/v3/sync?filter=1&since=s12697_1475292_6_14826_13441_24_4378_615_0_1&timeout=30000&user_id=%40signalbot%3Amydomain.dev
2024-01-06T08:20:37Z DBG Starting handling of transaction content={"pdu":0,"unstable_edu":4,"unstable_to_device":0} transaction_id=88562
2024-01-06T08:20:37Z DBG Finished dispatching events from transaction transaction_id=88562
2024-01-06T08:20:37Z DBG Starting handling of transaction content={"pdu":1,"unstable_edu":0,"unstable_to_device":0} transaction_id=88563
2024-01-06T08:20:37Z DBG Finished dispatching events from transaction transaction_id=88563
2024-01-06T08:20:37Z DBG Sent message checkpoint message_checkpoint={"event_id":"$5WfkNS2phabd0T4R1tfPgOX5wdZfSW58jQXyzOAXQ7w","event_type":"m.room.message","message_type":"m.image","reported_by":"BRIDGE","retry_num":0,"room_id":"!dCwPCGtRSWSHIyZkmT:mydomain.dev","status":"SUCCESS","step":"BRIDGE","timestamp":1704529237483}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xc6992c]

goroutine 1505 [running]:
go.mau.fi/mautrix-signal/pkg/signalmeow.(*Client).IsLoggedIn(...)
    /builds/mautrix/signal/pkg/signalmeow/client.go:103
main.(*Portal).handleMatrixMessages(0xc000699450, {0xc000392340?, 0xc0000fa6c0?})
    /builds/mautrix/signal/portal.go:348 +0x4c
main.(*Portal).messageLoop(0xc000699450)
    /builds/mautrix/signal/portal.go:338 +0xc5
created by main.(*SignalBridge).NewPortal in goroutine 1468
    /builds/mautrix/signal/portal.go:219 +0x4c5
2024-01-06T08:20:38Z INF Initializing bridge built_at="Jan  5 2024, 23:47:52" go_version=go1.21.5 name=mautrix-signal version=0.4.99+dev.6286fc9b
2024-01-06T08:20:38Z DBG Initializing database connection
2024-01-06T08:20:38Z DBG Initializing state store
2024-01-06T08:20:38Z DBG Initializing Matrix event processor
2024-01-06T08:20:38Z DBG Initializing Matrix event handler
2024-01-06T08:20:38Z INF Initializing libsignal version:0.38.0 component=libsignal file=rust/bridge/ffi/src/logging.rs line=99 target=signal_ffi::logging
2024-01-06T08:20:38Z INF Bridge initialization complete, starting...
sumnerevans commented 9 months ago

"different segfault" should be a separate issue

LukasNeuberger commented 9 months ago

Seemed related as the new segfault only ocurred after the fix, new segfault seems to be fixed with commit 40ffcd0. Sure, next time I will create a new issue.