Describe the bug
I found this problem while looking for template parts at specific offsets. All items inside a pfp.fields.Array containing Int/Float elements have a _pfp__offset of 0, instead of their actual positions in the parsed stream. It doesn't seems to be the case when the array items are structs.
To Reproduce
Here is a minimal test reproducing the problem:
def test_numerical_array_offset(self):
dom = self._test_parse_build(
"\xFF\x00\x00\x11\x11\x22\x22",
"""
char shift_by_one;
uint16 the_array[3];
"""
)
self.assertEqual(dom.the_array[0]._pfp__offset, 1)
self.assertEqual(dom.the_array[1]._pfp__offset, 3)
self.assertEqual(dom.the_array[2]._pfp__offset, 5)
It fails with:
Traceback (most recent call last):
File "pfp/tests/test_arrays.py", line 346, in test_numerical_array_offset
self.assertEqual(dom.the_array[0]._pfp__offset, 1)
File ".local/share/pyenv/versions/3.7.11/lib/python3.7/unittest/case.py", line 852, in assertEqual
assertion_func(first, second, msg=msg)
File ".local/share/pyenv/versions/3.7.11/lib/python3.7/unittest/case.py", line 845, in _baseAssertEqual
raise self.failureException(msg)
AssertionError: 0 != 1
Expected Behavior
The item's _pfp__offset should be set to the offset value of the item inside the parsed stream.
Describe the bug
I found this problem while looking for template parts at specific offsets. All items inside a
pfp.fields.Arraycontaining Int/Float elements have a_pfp__offsetof0, instead of their actual positions in the parsed stream. It doesn't seems to be the case when the array items are structs.To Reproduce
Here is a minimal test reproducing the problem:
It fails with:
Expected Behavior
The item's
_pfp__offsetshould be set to the offset value of the item inside the parsed stream.