diff --git a/.travis.yml b/.travis.yml
index 6f1e947..8fb569e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -12,3 +12,5 @@ matrix:
 script:
   - tox -e $INTERP-nocov,$INTERP-cov,qa,docs
   - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then tox -e $INTERP-diffcov; fi'
+before_script:
+  - echo 0 | sudo tee /proc/sys/net/ipv6/conf/all/disable_ipv6
diff --git a/aiosmtpd/smtp.py b/aiosmtpd/smtp.py
index 681732a..24661a6 100644
--- a/aiosmtpd/smtp.py
+++ b/aiosmtpd/smtp.py
@@ -234,10 +234,20 @@ class SMTP(asyncio.StreamReaderProtocol):
                 # re-encoded back to the original bytes when the SMTP command
                 # is handled.
                 if i < 0:
-                    command = line.upper().decode(encoding='ascii')
+                    try:
+                        command = line.upper().decode(encoding='ascii')
+                    except UnicodeDecodeError:
+                        await self.push('500 Error: bad syntax')
+                        continue
+
                     arg = None
                 else:
-                    command = line[:i].upper().decode(encoding='ascii')
+                    try:
+                        command = line[:i].upper().decode(encoding='ascii')
+                    except UnicodeDecodeError:
+                        await self.push('500 Error: bad syntax')
+                        continue
+
                     arg = line[i+1:].strip()
                     # Remote SMTP servers can send us UTF-8 content despite
                     # whether they've declared to do so or not.  Some old

Exception when parsing binary data
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.

``` python
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()
```
diff --git a/aiosmtpd/tests/test_smtp.py b/aiosmtpd/tests/test_smtp.py
index be1da96..975f252 100644
--- a/aiosmtpd/tests/test_smtp.py
+++ b/aiosmtpd/tests/test_smtp.py
@@ -197,6 +197,20 @@ class TestSMTP(unittest.TestCase):
         self.addCleanup(controller.stop)
         self.address = (controller.hostname, controller.port)
 
+    def test_binary(self):
+        with SMTP(*self.address) as client:
+            client.sock.send(b"\x80FAIL\r\n")
+            code, response = client.getreply()
+            self.assertEqual(code, 500)
+            self.assertEqual(response, b'Error: bad syntax')
+
+    def test_binary_space(self):
+        with SMTP(*self.address) as client:
+            client.sock.send(b"\x80 FAIL\r\n")
+            code, response = client.getreply()
+            self.assertEqual(code, 500)
+            self.assertEqual(response, b'Error: bad syntax')
+
     def test_helo(self):
         with SMTP(*self.address) as client:
             code, response = client.helo('example.com')

pip install -e .
parse_log_pytest
pytest
nose2 pytest
3.9
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
-e git+https://github.com/aio-libs/aiosmtpd.git@23b743be942ffd37f9c051c1f6efe0108ffd456d#egg=aiosmtpd
atpublic==5.1
exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
nose2==0.15.1
packaging @ file:///croot/packaging_1734472117206/work
pluggy @ file:///croot/pluggy_1733169602837/work
pytest @ file:///croot/pytest_1738938843180/work
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work

name: aiosmtpd
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - exceptiongroup=1.2.0=py39h06a4308_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - packaging=24.2=py39h06a4308_0
  - pip=25.0=py39h06a4308_0
  - pluggy=1.5.0=py39h06a4308_0
  - pytest=8.3.4=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tomli=2.0.1=py39h06a4308_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - atpublic==5.1
      - nose2==0.15.1
prefix: /opt/conda/envs/aiosmtpd

aiosmtpd/tests/test_smtp.py::TestSMTP::test_binary aiosmtpd/tests/test_smtp.py::TestSMTP::test_binary_space
aiosmtpd/tests/test_smtp.py::TestProtocol::test_empty_email aiosmtpd/tests/test_smtp.py::TestProtocol::test_honors_mail_delimeters aiosmtpd/tests/test_smtp.py::TestSMTP::test_data_invalid_params aiosmtpd/tests/test_smtp.py::TestSMTP::test_data_no_helo aiosmtpd/tests/test_smtp.py::TestSMTP::test_data_no_rcpt aiosmtpd/tests/test_smtp.py::TestSMTP::test_ehlo aiosmtpd/tests/test_smtp.py::TestSMTP::test_ehlo_duplicate aiosmtpd/tests/test_smtp.py::TestSMTP::test_ehlo_no_hostname aiosmtpd/tests/test_smtp.py::TestSMTP::test_ehlo_then_helo aiosmtpd/tests/test_smtp.py::TestSMTP::test_empty_command aiosmtpd/tests/test_smtp.py::TestSMTP::test_expn aiosmtpd/tests/test_smtp.py::TestSMTP::test_helo aiosmtpd/tests/test_smtp.py::TestSMTP::test_helo_duplicate aiosmtpd/tests/test_smtp.py::TestSMTP::test_helo_no_hostname aiosmtpd/tests/test_smtp.py::TestSMTP::test_helo_then_ehlo aiosmtpd/tests/test_smtp.py::TestSMTP::test_help aiosmtpd/tests/test_smtp.py::TestSMTP::test_help_bad_arg aiosmtpd/tests/test_smtp.py::TestSMTP::test_help_data aiosmtpd/tests/test_smtp.py::TestSMTP::test_help_ehlo aiosmtpd/tests/test_smtp.py::TestSMTP::test_help_helo aiosmtpd/tests/test_smtp.py::TestSMTP::test_help_mail aiosmtpd/tests/test_smtp.py::TestSMTP::test_help_mail_esmtp aiosmtpd/tests/test_smtp.py::TestSMTP::test_help_noop aiosmtpd/tests/test_smtp.py::TestSMTP::test_help_quit aiosmtpd/tests/test_smtp.py::TestSMTP::test_help_rcpt aiosmtpd/tests/test_smtp.py::TestSMTP::test_help_rcpt_esmtp aiosmtpd/tests/test_smtp.py::TestSMTP::test_help_rset aiosmtpd/tests/test_smtp.py::TestSMTP::test_help_vrfy aiosmtpd/tests/test_smtp.py::TestSMTP::test_mail_fail_parse_email aiosmtpd/tests/test_smtp.py::TestSMTP::test_mail_from_malformed aiosmtpd/tests/test_smtp.py::TestSMTP::test_mail_from_twice aiosmtpd/tests/test_smtp.py::TestSMTP::test_mail_malformed_params_esmtp aiosmtpd/tests/test_smtp.py::TestSMTP::test_mail_missing_params_esmtp aiosmtpd/tests/test_smtp.py::TestSMTP::test_mail_no_arg aiosmtpd/tests/test_smtp.py::TestSMTP::test_mail_no_from aiosmtpd/tests/test_smtp.py::TestSMTP::test_mail_no_helo aiosmtpd/tests/test_smtp.py::TestSMTP::test_mail_params_bad_syntax_esmtp aiosmtpd/tests/test_smtp.py::TestSMTP::test_mail_params_esmtp aiosmtpd/tests/test_smtp.py::TestSMTP::test_mail_params_no_esmtp aiosmtpd/tests/test_smtp.py::TestSMTP::test_mail_unrecognized_params_esmtp aiosmtpd/tests/test_smtp.py::TestSMTP::test_noop aiosmtpd/tests/test_smtp.py::TestSMTP::test_noop_with_arg aiosmtpd/tests/test_smtp.py::TestSMTP::test_quit aiosmtpd/tests/test_smtp.py::TestSMTP::test_quit_with_arg aiosmtpd/tests/test_smtp.py::TestSMTP::test_rcpt_fail_parse_email aiosmtpd/tests/test_smtp.py::TestSMTP::test_rcpt_no_address aiosmtpd/tests/test_smtp.py::TestSMTP::test_rcpt_no_arg aiosmtpd/tests/test_smtp.py::TestSMTP::test_rcpt_no_arg_esmtp aiosmtpd/tests/test_smtp.py::TestSMTP::test_rcpt_no_helo aiosmtpd/tests/test_smtp.py::TestSMTP::test_rcpt_no_mail aiosmtpd/tests/test_smtp.py::TestSMTP::test_rcpt_no_to aiosmtpd/tests/test_smtp.py::TestSMTP::test_rcpt_with_bad_params aiosmtpd/tests/test_smtp.py::TestSMTP::test_rcpt_with_params_no_esmtp aiosmtpd/tests/test_smtp.py::TestSMTP::test_rcpt_with_unknown_params aiosmtpd/tests/test_smtp.py::TestSMTP::test_rset aiosmtpd/tests/test_smtp.py::TestSMTP::test_rset_with_arg aiosmtpd/tests/test_smtp.py::TestSMTP::test_too_long_command aiosmtpd/tests/test_smtp.py::TestSMTP::test_unknown_command aiosmtpd/tests/test_smtp.py::TestSMTP::test_vrfy aiosmtpd/tests/test_smtp.py::TestSMTP::test_vrfy_no_arg aiosmtpd/tests/test_smtp.py::TestSMTP::test_vrfy_not_an_address aiosmtpd/tests/test_smtp.py::TestResetCommands::test_ehlo aiosmtpd/tests/test_smtp.py::TestResetCommands::test_helo aiosmtpd/tests/test_smtp.py::TestResetCommands::test_rset aiosmtpd/tests/test_smtp.py::TestSMTPWithController::test_bad_encodings aiosmtpd/tests/test_smtp.py::TestSMTPWithController::test_dots_escaped aiosmtpd/tests/test_smtp.py::TestSMTPWithController::test_esmtp_no_size_limit aiosmtpd/tests/test_smtp.py::TestSMTPWithController::test_exception_handler_exception aiosmtpd/tests/test_smtp.py::TestSMTPWithController::test_exception_handler_undescribable aiosmtpd/tests/test_smtp.py::TestSMTPWithController::test_mail_invalid_body aiosmtpd/tests/test_smtp.py::TestSMTPWithController::test_mail_with_compatible_smtputf8 aiosmtpd/tests/test_smtp.py::TestSMTPWithController::test_mail_with_incompatible_smtputf8 aiosmtpd/tests/test_smtp.py::TestSMTPWithController::test_mail_with_size_too_large aiosmtpd/tests/test_smtp.py::TestSMTPWithController::test_mail_with_unrequited_smtputf8 aiosmtpd/tests/test_smtp.py::TestSMTPWithController::test_process_message_error aiosmtpd/tests/test_smtp.py::TestSMTPWithController::test_too_long_message_body aiosmtpd/tests/test_smtp.py::TestSMTPWithController::test_unexpected_errors aiosmtpd/tests/test_smtp.py::TestSMTPWithController::test_unexpected_errors_custom_response aiosmtpd/tests/test_smtp.py::TestSMTPWithController::test_unexpected_errors_unhandled aiosmtpd/tests/test_smtp.py::TestCustomizations::test_custom_greeting aiosmtpd/tests/test_smtp.py::TestCustomizations::test_custom_hostname aiosmtpd/tests/test_smtp.py::TestCustomizations::test_default_greeting aiosmtpd/tests/test_smtp.py::TestCustomizations::test_mail_invalid_body_param aiosmtpd/tests/test_smtp.py::TestClientCrash::test_close_in_command aiosmtpd/tests/test_smtp.py::TestClientCrash::test_close_in_data aiosmtpd/tests/test_smtp.py::TestClientCrash::test_connection_reset_during_DATA aiosmtpd/tests/test_smtp.py::TestClientCrash::test_connection_reset_during_command aiosmtpd/tests/test_smtp.py::TestStrictASCII::test_bad_encoded_param aiosmtpd/tests/test_smtp.py::TestStrictASCII::test_data aiosmtpd/tests/test_smtp.py::TestStrictASCII::test_ehlo aiosmtpd/tests/test_smtp.py::TestStrictASCII::test_mail_param aiosmtpd/tests/test_smtp.py::TestSleepingHandler::test_close_after_helo
.travis.yml aiosmtpd/smtp.py
.travis.yml aiosmtpd/smtp.py