fix: repair LinuxSLL.set_addr() array type mismatch in zero-padding#2148
Open
VoidChecksum wants to merge 1 commit intofortra:masterfrom
Open
fix: repair LinuxSLL.set_addr() array type mismatch in zero-padding#2148VoidChecksum wants to merge 1 commit intofortra:masterfrom
VoidChecksum wants to merge 1 commit intofortra:masterfrom
Conversation
set_addr() passes raw bytes to array.array.extend(), which is not
guaranteed by the array API across Python versions. Wrap the padding
in array.array('B', ...) to ensure type-correct array operations.
Fixes fortra#2093
There was a problem hiding this comment.
Pull request overview
This PR updates LinuxSLL address padding logic in ImpactPacket.py by changing how zero-bytes are appended when the provided address is shorter than 8 bytes.
Changes:
- Adjusted
LinuxSLL.set_addr()to extend the address buffer using anarray.array('B', ...)wrapper around the padding bytes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| addr = array.array('B', addr[:8]) | ||
| if len(addr) < 8: | ||
| addr.extend(b'\0' * (8 - len(addr))) | ||
| addr.extend(array.array('B', b'\0' * (8 - len(addr)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LinuxSLL.set_addr()passes rawbytestoarray.array.extend(), which is not guaranteed by the array API across Python versions and can raiseTypeError.Root cause: In
set_addr(), theaddrvariable is anarray.array('B', ...), butaddr.extend(b'\0' * n)passes abytesobject. While some Python versions coercebytesto array-compatible input inextend(), this is not guaranteed — the array documentation specifies thatextend()accepts an iterable of the array's type, not arbitrary bytes.Fix: Wrap the zero-padding bytes in
array.array('B', ...)before passing toextend().Reproduction
Changes
impacket/ImpactPacket.pyline 734:Test plan
set_addr(b'\x01\x02')— short address pads to 8 bytes without TypeErrorset_addr(b'\x01\x02\x03\x04\x05\x06\x07\x08')— full-length address, no padding pathget_addr()round-trips correctly afterset_addr()Fixes #2093