Source-Python-Dev-Team / Source.Python

This plugin aims to use boost::python and create an easily accessible wrapper around the Source Engine API for scripter use.
http://forums.sourcepython.com
GNU General Public License v3.0
164 stars 32 forks source link

messages - UnicodeDecodeError #452

Closed Frag1337 closed 2 years ago

Frag1337 commented 2 years ago

Hey,

I was just checking my logs and found this in here:

Client "🖤🇺🇦МАША🇺🇦ðŸ–" connected (X.XXX.XXX.XXX:27005).
[Source.Python] 
[SP] Caught an Exception:
Traceback (most recent call last):
  File "../addons/source-python/packages/source-python/messages/hooks.py", line 278, in _pre_message_end
    data = impl.read(buffer_read)
  File "../addons/source-python/packages/source-python/messages/impl.py", line 113, in read
    return cls.read_bitbuffer(buffer)
  File "../addons/source-python/packages/source-python/messages/impl.py", line 159, in read_bitbuffer
    param1=buffer.read_string(),

UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 28-30: unexpected end of data

Is this sp related or something else?

srpg commented 2 years ago

Hey,

I was just checking my logs and found this in here:

Client "🖤🇺🇦МÐ�ШÐ�🇺🇦ðŸ–" connected (X.XXX.XXX.XXX:27005).
[Source.Python] 
[SP] Caught an Exception:
Traceback (most recent call last):
  File "../addons/source-python/packages/source-python/messages/hooks.py", line 278, in _pre_message_end
    data = impl.read(buffer_read)
  File "../addons/source-python/packages/source-python/messages/impl.py", line 113, in read
    return cls.read_bitbuffer(buffer)
  File "../addons/source-python/packages/source-python/messages/impl.py", line 159, in read_bitbuffer
    param1=buffer.read_string(),

UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 28-30: unexpected end of data

Is this sp related or something else?

Hi, I think it is, i have been getting those errors sometimes aswell, only thought when special name player joins, like chinese name player have

Ayuto commented 2 years ago

Yes, this seems to be an issue with our user message hook.

Which user message hooka are you using? The issue shouldn't occur if no SP plugin is loaded.

srpg commented 2 years ago

Yes, this seems to be an issue with our user message hook.

Which user message hooka are you using? The issue shouldn't occur if no SP plugin is loaded.

I use it only in:

@HookUserMessage('SayText2') def _saytext2_hook(recipients, data): if data['index'] == 0: return True recipients.remove_all_players()

Frag1337 commented 2 years ago

I'm also using SayText2 hook.

Yes, this seems to be an issue with our user message hook. Which user message hooka are you using? The issue shouldn't occur if no SP plugin is loaded.

I use it only in:

@HookUserMessage('SayText2') def _saytext2_hook(recipients, data): if data['index'] == 0: return True recipients.remove_all_players()

I'm using SayText2 hook aswell.

jordanbriere commented 2 years ago

param1=buffer.read_string()

Sounds like it's related to #27 and #186. Based on these issues, this exception can be reproduced for param1 with:

from messages.hooks import HookUserMessage
from players.entity import Player

@HookUserMessage('SayText2')
def _(recipients, data):
    ...

pl = Player(1)
pl.say('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa£')

And for param2 with:

from messages.hooks import HookUserMessage
from players.entity import Player

@HookUserMessage('SayText2')
def _(recipients, data):
    ...

pl = Player(1)
pl.name = '┼ N‡GH†MΔƦΣ CRΣ3PƦ ⺠'
pl.say('...')

These should now be fixed into https://github.com/Source-Python-Dev-Team/Source.Python/commit/9d17a696f93a681a1bf7830b72a714ee25fb47f1.

srpg commented 2 years ago

Just tested the fix in my linux server, when i used that code, it still showed different kind error.

[2022-08-26 13:47:08]: [SP] Loading plugin 'test' [2022-08-26 13:47:08]: Could not find steamerrorreporter binary. Any minidumps will be uploaded in-processUnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 139: invalid continuation byte [2022-08-26 13:47:08]: [Bots] Seth: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa� [2022-08-26 13:47:08]: [SP] Successfully loaded plugin 'test`

jordanbriere commented 2 years ago

position 139

The first reproducible code above should raise at location 126. The fact it shows 139 for you means the message is already formatted and include [Bots] Seth:. What is the complete traceback? What game? Output of sp info? Are you sure you properly updated your core.so and impl.py?

jordanbriere commented 2 years ago

Okay, I was able to reproduce it. It's caused by OnServerOutput.

EDIT: Should be fixed into https://github.com/Source-Python-Dev-Team/Source.Python/commit/fec03ca4919936f4eae15168c30059efea694d09.

srpg commented 2 years ago

I can confirm that the latest commit fixed the error