Skip to content

fix: repair LinuxSLL.set_addr() array type mismatch in zero-padding#2148

Open
VoidChecksum wants to merge 1 commit intofortra:masterfrom
VoidChecksum:fix/linux-sll-setters
Open

fix: repair LinuxSLL.set_addr() array type mismatch in zero-padding#2148
VoidChecksum wants to merge 1 commit intofortra:masterfrom
VoidChecksum:fix/linux-sll-setters

Conversation

@VoidChecksum
Copy link

Summary

LinuxSLL.set_addr() passes raw bytes to array.array.extend(), which is not guaranteed by the array API across Python versions and can raise TypeError.

Root cause: In set_addr(), the addr variable is an array.array('B', ...), but addr.extend(b'\0' * n) passes a bytes object. While some Python versions coerce bytes to array-compatible input in extend(), this is not guaranteed — the array documentation specifies that extend() accepts an iterable of the array's type, not arbitrary bytes.

Fix: Wrap the zero-padding bytes in array.array('B', ...) before passing to extend().

Reproduction

from impacket.ImpactPacket import LinuxSLL

sll = LinuxSLL()
sll.set_addr(b'\x01\x02')  # May raise TypeError during padding

Changes

impacket/ImpactPacket.py line 734:

 if len(addr) < 8:
-    addr.extend(b'\0' * (8 - len(addr)))
+    addr.extend(array.array('B', b'\0' * (8 - len(addr))))

Test plan

  • set_addr(b'\x01\x02') — short address pads to 8 bytes without TypeError
  • set_addr(b'\x01\x02\x03\x04\x05\x06\x07\x08') — full-length address, no padding path
  • get_addr() round-trips correctly after set_addr()
  • Consistent behavior across Python 3.10, 3.11, 3.12, 3.13

Fixes #2093

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
Copilot AI review requested due to automatic review settings March 15, 2026 18:33
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 an array.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))))
@anadrianmanrique anadrianmanrique added the in review This issue or pull request is being analyzed label Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in review This issue or pull request is being analyzed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImpactPacket: LinuxSLL setters are broken (set_arphdr, set_addr)

4 participants