Non-unicode filenames causes UnicodeEncodeError on python3

Open
#68 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
c, python
Domain
security

Research direction

Reproduce the Linux example using pathlib, os.fsdecode, and rules.match() with the undecodable filename. Start at the rules.match() call and determine how filenames containing surrogate characters should be handled; done means the example no longer raises UnicodeEncodeError while scanning the file.

Written by the indexing model from the issue text.

Description

On linux, file names are actually bytes, not unicode. Yara can not scan file containing non-unicode bytes:

import pathlib
import os
import yara
p = pathlib.Path(os.fsdecode(b'/tmp/\x44\xf9'))
p.write_text('malware')
rules = yara.compile('main.yara')
rules.match(str(p)) # UnicodeEncodeError: 'utf-8' codec can't encode character '\udcf9' in position 6: surrogates not allowed

How should I decode bytes filename to pass it to match() ?

Dominant language
C
Stars
754
Forks
190
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from VirusTotal/yara-python

All issues in VirusTotal/yara-python

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.