Skip to content

Handle decoding errors in file inspection during filtering #3373

Open

Description

@sentry

Sentry Issue: BOT-436

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf5 in position 14: invalid start byte
  File "bot/exts/filtering/filtering.py", line 237, in on_message
    await _extract_text_file_content(a)
  File "bot/exts/filtering/filtering.py", line 73, in _extract_text_file_content
    file_lines = file_content_bytes.decode(file_encoding).splitlines()

Unhandled exception in on_message.

It's not obvious to me what would be appropriate here. Block the file? Ignore unknown characters?

Activity

  1. added
    t: bugSomething isn't working
    a: filtersRelated to message filters: (antimalware, antispam, filtering, token_remover)
    on Aug 17, 2025
  2. mbaruh commented on Aug 17, 2025

    @mbaruh
    Member

    @swfarnsworth your input would be appreciated

  3. swfarnsworth commented on Aug 17, 2025

    @swfarnsworth
    Contributor

    @mbaruh I think this is the first time this has happened?
    We could just add errors='ignore'.

  4. wookie184 commented on Sep 15, 2025

    @wookie184
    Contributor

    In this case it seems like a user uploaded a zip file with a txt extension. I assume the same could happen if you tried to share an executable with a txt extension? If so it could be an indication of somebody trying to bypass filters, though seemlingly rare so not a high priority.

  5. onerandomusername commented on Oct 22, 2025

    @onerandomusername
    Contributor

    What was the value of file_encoding in this error?

  6. wookie184 commented on Nov 20, 2025

    @wookie184
    Contributor

    What was the value of file_encoding in this error?

    "utf-8"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: filtersRelated to message filters: (antimalware, antispam, filtering, token_remover)p: 1 - highHigh Prioritys: planningDiscussing detailst: bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions