Skip to content
This repository was archived by the owner on Nov 20, 2023. It is now read-only.

Invalid payload when array size greater than 255 #54

Open
hans00 opened this issue Mar 1, 2023 · 5 comments
Open

Invalid payload when array size greater than 255 #54

hans00 opened this issue Mar 1, 2023 · 5 comments
Assignees

Comments

@hans00
Copy link
Contributor

hans00 commented Mar 1, 2023

Maybe all len( xxx ) are same.

P.S. This mainly occur on getContacts in large group.

@WEDeach
Copy link
Member

WEDeach commented Mar 1, 2023

Any error log?

@WEDeach WEDeach added the question Further information is requested label Mar 1, 2023
@hans00
Copy link
Contributor Author

hans00 commented Mar 1, 2023

File "/opt/sango_new_bot/events/commands/search_player.py", line 7, in exec
  members = line.getContacts(members)
File "/opt/sango_new_bot/linex/wrapper.py", line 546, in getContacts
  return [ Contact(g) for g in super().getContacts(mids) ]
File "/usr/local/lib/python3.10/dist-packages/CHRLINE/services/TalkService.py", line 469, in getContacts
  return self.postPackDataAndGetUnpackRespData(
File "/usr/local/lib/python3.10/dist-packages/CHRLINE/models.py", line 425, in postPackDataAndGetUnpackRespData
  data = bdata = bytes(bdata)

In my inspect, the root cause is here

I'm only know in spec it is int32 BE.

https://github.com/apache/thrift/blob/master/doc/specs/thrift-binary-protocol.md#binary-encoding

@WEDeach
Copy link
Member

WEDeach commented Mar 1, 2023

Apparently this is early code and it's not well supported.

Try use params = [[15, 2 [11, mids]]]

@WEDeach
Copy link
Member

WEDeach commented Mar 1, 2023

full code:

def getContacts(self, mid: str):
    METHOD_NAME = "getContacts"
    params = [[15, 2, [11, mids]]]
    sqrd = self.generateDummyProtocol(METHOD_NAME, params, 3)
    return self.postPackDataAndGetUnpackRespData(
        self.LINE_NORMAL_ENDPOINT, sqrd, readWith=f"TalkService.{METHOD_NAME}"
    )

but how?
curr code is using hardcore-code:

sqrd = [
    128,  1,0,1, 0,0, 0,11,103,101,116, 67,111,110,116,97,99,116,115, 0,0,0,0,15,0,2,11,0,0,0, len(mids)
#  (PROTO)(SEQ)(                   CALL NAME                           )(               PARAMS                  )
#                                                                        Type 15, Fid 2,  String(Type 11) list
]

first byte indicates the protocol type (Binary), which limits the endpoints it can request (/S3).

In order to get better support, use generateDummyProtocol() to generate the formats of various protocols, which also simplifies the writing of parameters (REF DummyProtocol.md

migrating old code to new code is not difficult, but I didn't do it because it was too time-consuming.

@WEDeach WEDeach removed the question Further information is requested label Mar 1, 2023
@hans00
Copy link
Contributor Author

hans00 commented Mar 1, 2023

Ok, thanks
Maybe I find time to migrate those obviously buggy codes.

@WEDeach WEDeach self-assigned this Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants