-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow recovery from corrupted items in Enum.read_many()
- Loading branch information
1 parent
2eb2026
commit 5ba290b
Showing
2 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import unittest | ||
|
||
from xpdt import NameSpace, StructDef, MemberDef, BaseType | ||
|
||
class Test_RoundTrips(unittest.TestCase): | ||
def setUp(self): | ||
self.code = NameSpace( | ||
structs=( | ||
StructDef( | ||
name='Item', | ||
members=( | ||
MemberDef('b', BaseType.bytes), | ||
MemberDef('s', BaseType.utf8), | ||
), | ||
discriminant=0xfacebeef, | ||
), | ||
), | ||
name='test', | ||
).gen_dynamic_python() | ||
|
||
def test_item(self): | ||
orig = self.code.Item(b'\x00' * 4, 'Malkovich') | ||
b = orig._enum_wrap(ts) | ||
clone, = self.code.Test.read_many(memoryview(b)) | ||
self.assertEqual((ts, orig), clone) | ||
|
||
def test_item(self): | ||
bad_utf = b'\xc3\x28' | ||
ts = 0 | ||
|
||
orig = self.code.Item(b'\xff', 'AA') | ||
|
||
a = orig._enum_wrap(ts) | ||
a = a[:-len(bad_utf)] + bad_utf | ||
|
||
b = orig._enum_wrap(ts) | ||
|
||
first, second = list(self.code.Test.read_many(memoryview(a + b))) | ||
self.assertIsInstance(first, UnicodeDecodeError) | ||
self.assertEqual(second, (ts, orig)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters