You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Adding data to existing segment may fail depending on how segment was previously created #53
In this case the data provided by .elf file pathElf and the data inserted afterwards overlaps, therefore overwrite=True was used.
Observed:
File "/usr/lib/python3/dist-packages/bincopy.py", line 1107, in add_binary
self._segments.add(Segment(address,
File "/usr/lib/python3/dist-packages/bincopy.py", line 605, in add
s.add_data(segment.minimum_address,
File "/usr/lib/python3/dist-packages/bincopy.py", line 444, in add_data
self.data[self_data_offset:self_data_offset + len(data)] = data
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'bytes' object does not support item assignment
Expectation:
Data was successfully replaced/overwritten/modified.
add_binary for initial data creation is not affected as it creates a segment based on a bytearray:
binaryFile=bincopy.BinFile()
binaryFile.add_binary(binaryFileElf.as_binary())
binaryFile.add_binary(data, address=0, overwrite=True) # This works as add_binary uses a bytearray
Suggestion: potentially specifying self.data of class Segment to always be a mutable bytearray could be an option if there is no need for immutable segments.
Activity
eerimoq commentedon Feb 23, 2026
Nice find, segments should always be bytearray. feel free to submit a PR with a fix
projms-intive commentedon Feb 24, 2026
PR proposed and merged: #54