Skip to content

Adds conversion to bytearray within Segment#54

Merged
eerimoq merged 1 commit intoeerimoq:masterfrom
projms-intive:elfmodifyfix
Feb 24, 2026
Merged

Adds conversion to bytearray within Segment#54
eerimoq merged 1 commit intoeerimoq:masterfrom
projms-intive:elfmodifyfix

Conversation

@projms-intive
Copy link
Contributor

@projms-intive projms-intive commented Feb 24, 2026

Fix for #53

Previously, depending on how a Segment was created, the internal data may have been stored as an immutable bytes object. This caused issues with modifying operations.

Now, the best I've found to come up with an as small as possible fix was a simple conversion to bytearray within Segment.__init__().

I've also checked out python type-hints, but these do not enforce a type during runtime.

I can not guarantee that self.data will never be internally assigned a bytes object in some obscure way. (And I unfortunately don't have enough time to do a full analysis to catch every edge-case). For a sanity check I modified the Segment equal operator and executed all tests

def __eq__(self, other):
        print(type(self.data) == type(bytearray()))

Before change: I got a mix of True and False, newly added unit test was failed
After change: I only saw True, newly added unit test succeeded

On my end all unit tests are successful.

Hope it helps, and let me know if you need anything else for this PR.

Previously, depending on how a Segment was created, the internal
data may have been stored as an immutable bytes object. This caused
issues with modifying operations.
@eerimoq
Copy link
Owner

eerimoq commented Feb 24, 2026

I like it.

@eerimoq eerimoq merged commit 42c4a6e into eerimoq:master Feb 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants