molejar / pyFDT

Flattened Device Tree Python Module
Apache License 2.0
37 stars 13 forks source link

Parsing binary includes is broken #24

Open fraove opened 10 months ago

fraove commented 10 months ago

Parsing a dts containing a binary include (/incbin/) gives me the following exception using python 3.7 and pyFDT 0.3.3:

Traceback (most recent call last):
  File "./test.py", line 9, in <module>
    tree = fdt.parse_dts(dts)
  File "<...>/python3.7/site-packages/fdt/__init__.py", line 505, in parse_dts
    prop_obj = PropIncBin(prop_name, prop_data, os.path.split(file_path)[1])
  File "<...>/python3.7/site-packages/fdt/items.py", line 469, in __init__
    super().__init__(name, data)
  File "<...>/site-packages/fdt/items.py", line 378, in __init__
    self.data = bytearray(args)
TypeError: 'bytes' object cannot be interpreted as an integer

Code to reproduce:

import fdt

dts = """/dts-v1/;

/ {
  data = /incbin/("data.bin");
};
"""

tree = fdt.parse_dts(dts)
fraove commented 10 months ago

I believe this is broken in this commit: https://github.com/molejar/pyFDT/commit/bcf94d955939394aeb0c576683eca87208e5a5a9

Since this change the PropBytes's initializer takes *args in addition to data:

-    def __init__(self, name, data=None):
+    def __init__(self, name, *args, data=None):

Test code is adjusted accordingly:

-    prop1 = fdt.PropBytes('prop', [0x10, 0x50, 0x00])
+    prop1 = fdt.PropBytes('prop', data=b"\x10\x50\x00")

But there is no corresponding change in the initializer of PropIncBin:

https://github.com/molejar/pyFDT/blob/90186c53ee2fba25a7a515fba5debde2e07f9c08/fdt/items.py#L469

(And apparently no test coverage for PropIncBin ;))