Commit 70eea4c
authored
Don't abort scan on non-UTF-8 module dictionary keys (#280)
convert_dictionary_to_python used PyDict_SetItemString, which decodes the
key as strict UTF-8. YARA module dictionary keys are SIZED_STRING values
holding arbitrary bytes (for instance pe.version_info keys read straight
from the binary), so a non-UTF-8 key raised UnicodeDecodeError. That
exception propagated out of the modules_callback as a SystemError and
aborted the whole scan.
Build the key explicitly with a tolerant decoder (PyUnicode_DecodeUTF8
with the 'replace' handler) and use the key length so embedded NULs are
handled too. Keys stay str, so this is not a breaking change: valid keys
are unchanged and invalid bytes become U+FFFD instead of aborting.
Fixes #273
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>1 parent fb240bc commit 70eea4c
1 file changed
Lines changed: 19 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
818 | 818 | | |
819 | 819 | | |
820 | 820 | | |
821 | | - | |
822 | | - | |
823 | | - | |
824 | | - | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
825 | 840 | | |
826 | 841 | | |
827 | 842 | | |
| |||
0 commit comments