diff --git a/scapy/utils.py b/scapy/utils.py index 03ad0fcd364..facd90d8803 100644 --- a/scapy/utils.py +++ b/scapy/utils.py @@ -530,7 +530,7 @@ def hexdiff( if dox: xd = y j = 0 - while not linex[j]: + while j < len(linex) and not linex[j]: j += 1 xd -= 1 print(colorize[doy - dox]("%04x" % xd), end=' ') @@ -541,7 +541,7 @@ def hexdiff( if doy: yd = y j = 0 - while not liney[j]: + while j < len(liney) and not liney[j]: j += 1 yd -= 1 print(colorize[doy - dox]("%04x" % yd), end=' ') diff --git a/test/regression.uts b/test/regression.uts index 53dcad0d910..af284e224a6 100644 --- a/test/regression.uts +++ b/test/regression.uts @@ -978,6 +978,11 @@ assert expected_ret2 in ret2 hexdiff(b"abc", IP() / TCP()) hexdiff(IP() / TCP(), b"abc") +# Test that hexdiff does not crash on a 16-byte row that is entirely a gap +# on one side (GH #5034) + +hexdiff(b"B" * 9 + b"\x08", b"A" + b"\x08" + b"A" * 23, algo="difflib") + = Test mysummary functions - Ether p = Ether(dst="ff:ff:ff:ff:ff:ff", src="ff:ff:ff:ff:ff:ff", type=0x9000)