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 when parsing binary data #142

Closed
edeca opened this issue Apr 4, 2018 · 0 comments
Closed

Exception when parsing binary data #142

edeca opened this issue Apr 4, 2018 · 0 comments

Comments

@edeca
Copy link

edeca commented Apr 4, 2018

aiosmtpd will try to ASCII decode binary data as SMTP commands, raising a UnicodeDecodeError. A simple test case that triggers this is shown at the end of this report. This can be caught by a generic exception handler, however it would be better to do this inside the library.

This can be trivially fixed with a try/except handler. PR incoming.

from base64 import b64decode
import socket


TCP_IP = '127.0.0.1'
TCP_PORT = 8025
BUFFER_SIZE = 1024

RAW = "gUMBAwMBGgAAACAAwDAAwCwAwCgAwCQAwBQAwAoAwCIAwCEAAKMAAJ8AAGsAAGoAADkAADgAAIgAAIcAwBkAwCAAwDIAwC4AwCoAwCYAwA8AwAUAAJ0AAD0AADUAAIQAwBIAwAgAwBwAwBsAABYAABMAwBcAwBoAwA0AwAMAAAoHAMAAwC8AwCsAwCcAwCMAwBMAwAkAwB8AwB4AAKIAAJ4AAGcAAEAAADMAADIAAJoAAJkAAEUAAEQAwBgAwB0AwDEAwC0AwCkAwCUAwA4AwAQAAJwAADwAAC8AAJYAAEEAAAcAwBEAwAcAwBYAwAwAwAIAAAUAAAQFAIADAIABAIAAABUAABIAAAkGAEAAABQAABEAAAgAAAYAAAMEAIACAIAAAP8cXF6WB1DBTAUUZfksmYhwy/mtOvciiLZb+ZNMaF/tYg=="
MESSAGE = b64decode(RAW)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
data = s.recv(BUFFER_SIZE)
print("Received: {}".format(data))
s.send(MESSAGE)
data = s.recv(BUFFER_SIZE)
print("Received: {}".format(data))
s.close()
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