8000
Skip to content

wrong _pfp__offset for primitive array items #139

Description

@michaelmera

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.

Metadata

Metadata

Assignees

Labels

bugneeds-triageA fresh user-reported issue that needs triage (i.e. is not a concrete-issue)

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

0