impacket icon indicating copy to clipboard operation
impacket copied to clipboard

bug fix issue #1675

Open NtAlexio2 opened this issue 1 year ago • 2 comments

This PR fixes issue reported on #1675. The patch decodes bytes returned from getData() by default sys.stdout encoding. The root cause of the bug is drop Python2 supporting.

NtAlexio2 avatar Jan 12 '24 17:01 NtAlexio2

Hi, the proposed solution will break on certain scenarios:

  • self.getData() can return a bytes object which may not be a valid unicode string for the selected encoding
  • Here's a specific example:
    • stdout.encoding => 'utf-8'
    • self.getData() => b'\xc3'
    • b'\xc3'.decode('utf-8') throws an exception: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 0: unexpected end of data

I think that a better approach would be to represent that buffer in an encoding agnostic way, maybe by using binascii.hexlify(self.getData())

alexisbalbachan avatar Feb 15 '24 15:02 alexisbalbachan

Thanks for your review. I applied your suggestion. Please recheck <3

NtAlexio2 avatar Feb 17 '24 20:02 NtAlexio2