kenorb-contrib / tg

`telegram-cli` for Telegram IM
https://github.com/telegramdesktop/tdesktop
GNU General Public License v2.0
382 stars 52 forks source link

Exception in tgl_do_delete_msg Python interface #48

Open GLinnik21 opened 2 years ago

GLinnik21 commented 2 years ago

Environment

Python 3.9 macOS 11.5.2 (20G95) MacBook Pro M1 (arm64e) Compiled with Python support and --disable-liblua

The issue

I get the following exception when I try to execute tgl.delete_msg(msg.id)

SIGNAL received
S0   telegram-cli                        0x0000000104216918 print_backtrace + 48
1   telegram-cli                        0x0000000104216a0c termination_signal_handler + 176
2   libsystem_platform.dylib            0x000000019860ec44 _sigtramp + 56
3   telegram-cli                        0x0000000104237cec py_do_all + 5240
4   telegram-cli                        0x0000000104237cec py_do_all + 5240
5   telegram-cli                        0x0000000104217670 net_loop + 228
6   telegram-cli                        0x0000000104219e20 loop + 704
7   telegram-cli                        0x0000000104215e50 inner_main + 12
8   telegram-cli                        0x0000000104216f98 main + 1060
9   libdyld.dylib                       0x00000001985e1430 start + 4

Attaching to lldb gives the following information:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x6db93)
  * frame #0: 0x0000000100630ab4 telegram-cli`tgl_do_delete_msg(TLS=0x0000000153009c00, _msg_id=0x000000000006db93, callback=(telegram-cli`py_empty_cb at python-tg.c:500), callback_extra=0x000000010e416040) at queries.c:4191:29
    frame #1: 0x0000000100617cec telegram-cli`py_do_all at python-tg.c:1063:9
    frame #2: 0x00000001005f7670 telegram-cli`net_loop at loop.c:334:7
    frame #3: 0x00000001005f9e20 telegram-cli`loop at loop.c:878:3
    frame #4: 0x00000001005f5e50 telegram-cli`inner_main at main.c:455:3
    frame #5: 0x00000001005f6f98 telegram-cli`main(argc=5, argv=0x000000016f80b718) at main.c:1036:3
    frame #6: 0x00000001985e1430 libdyld.dylib`start + 4

It seems that the error in the following code: https://github.com/kenorb-contrib/tgl/blob/57f1bc41ae13297e6c3e23ac465fd45ec6659f50/queries.c#L4191

void tgl_do_delete_msg (struct tgl_state *TLS, tgl_message_id_t *_msg_id, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra) {
  tgl_message_id_t msg_id = *_msg_id;
  if (msg_id.peer_type == TGL_PEER_TEMP_ID) {
    msg_id = tgl_convert_temp_msg_id (TLS, msg_id);
  }

This code tries to dereference _msg_id variable that is an integer not a pointer (value: 449427 (0x6db93)) that was passed from python interface code: https://github.com/kenorb-contrib/tg/blob/a2343474b315832dbbfbf9aea122165f360ba8f5/python-tg.c#L1060-L1066 It seems that PY_MSG_ID simply casts integer from Python function to tgl_message_id_t* type that is wrong