Skip to content

Commit 8863c05

Browse files
issue 37: test demonstrates issue, and quick continue-parsing fix
1 parent b4f6586 commit 8863c05

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

tests/test_issue_37.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,58 @@
1+
import os
2+
import pytest
3+
14
import Evtx.Evtx as evtx
25

36
from fixtures import *
47

58

6-
def test_render_records(data_path):
9+
def test_corrupt_ascii_example(data_path):
10+
'''
11+
regression test demonstrating issue 37.
12+
13+
Args:
14+
data_path (str): the file system path of the test directory.
15+
'''
16+
# record number two contains a QNAME xml element
17+
# with an ASCII text value that is invalid ASCII:
18+
#
19+
# 000002E0: 31 39 33 2E 31 2E 193.1.
20+
# 000002F0: 33 36 2E 31 32 31 30 2E 39 2E 31 35 2E 32 30 32 36.1210.9.15.202
21+
# 00000300: 01 62 2E 5F 64 6E 73 2D 73 64 2E 5F 75 64 70 2E .b._dns-sd._udp.
22+
# 00000310: 40 A6 35 01 2E @.5..
23+
# ^^ ^^ ^^
24+
#
25+
with pytest.raises(UnicodeDecodeError):
26+
with evtx.Evtx(os.path.join(data_path, 'dns_log_malformed.evtx')) as log:
27+
for chunk in log.chunks():
28+
for record in chunk.records():
29+
assert record.xml() is not None
30+
31+
32+
def test_continue_parsing_after_corrupt_ascii(data_path):
733
'''
834
regression test demonstrating issue 37.
935
1036
Args:
1137
data_path (str): the file system path of the test directory.
1238
'''
39+
attempted = 0
40+
completed = 0
41+
failed = 0
1342
with evtx.Evtx(os.path.join(data_path, 'dns_log_malformed.evtx')) as log:
1443
for chunk in log.chunks():
1544
for record in chunk.records():
16-
assert record.xml() is not None
45+
try:
46+
attempted += 1
47+
assert record.xml() is not None
48+
completed += 1
49+
except UnicodeDecodeError:
50+
failed += 1
51+
52+
# this small log file has exactly five records.
53+
assert attempted == 5
54+
# the first record is valid.
55+
assert completed == 1
56+
# however the remaining four have corrupted ASCII strings,
57+
# which we are unable to decode.
58+
assert failed == 4

0 commit comments

Comments
 (0)