Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in tgl_do_delete_msg Python interface #48

Open
GLinnik21 opened this issue Oct 13, 2021 · 0 comments
Open

Exception in tgl_do_delete_msg Python interface #48

GLinnik21 opened this issue Oct 13, 2021 · 0 comments

Comments

@GLinnik21
Copy link

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:

tg/python-tg.c

Lines 1060 to 1066 in a234347

case pq_delete_msg:
case pq_restore_msg:
if(PyArg_ParseTuple(args, "l|O", &msg_id, &cb_extra))
tgl_do_delete_msg (TLS, PY_MSG_ID(msg_id), py_empty_cb, cb_extra);
else
PyErr_Print();
break;

It seems that PY_MSG_ID simply casts integer from Python function to tgl_message_id_t* type that is wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant