Skip to content

fix: bounds-check hexdiff() offset-skip loop to prevent IndexError#5036

Merged
polybassa merged 1 commit into
secdev:masterfrom
citizen204:fix-5034-hexdiff-indexerror
Jul 4, 2026
Merged

fix: bounds-check hexdiff() offset-skip loop to prevent IndexError#5036
polybassa merged 1 commit into
secdev:masterfrom
citizen204:fix-5034-hexdiff-indexerror

Conversation

@citizen204

Copy link
Copy Markdown
Contributor

Summary

hexdiff() raises IndexError: list index out of range when the difflib alignment (algo='difflib') produces a 16-byte display row that is entirely a "gap" on one side (a run of >=16 aligned insertions/deletions). The loop that skips leading empty cells to compute the row's starting offset had no bounds check and walked off the end of the row.

Fixes #5034

Changes

  • scapy/utils.py: added j < len(linex) / j < len(liney) bounds checks to the two offset-skip while loops in hexdiff(), so the loop stops once it reaches the end of a fully-gapped row instead of indexing past it.
  • test/regression.uts: added a regression test using the minimal reproduction from the issue (hexdiff(b"B"*9 + b"\x08", b"A" + b"\x08" + b"A"*23, algo="difflib")), which previously raised IndexError and now completes without crashing.

AI-Assisted: yes (Claude Sonnet 5)

hexdiff() raised IndexError when the difflib alignment produced a
16-byte display row that was entirely a gap on one side. The loop
that skips leading empty cells to compute the row offset had no
bounds check and walked off the end of the row.

Fixes secdev#5034

AI-Assisted: yes (Claude Sonnet 5)
@polybassa

Copy link
Copy Markdown
Contributor

Thanks for the fix

@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.69%. Comparing base (f967117) to head (d8e8d29).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5036      +/-   ##
==========================================
- Coverage   80.21%   79.69%   -0.52%     
==========================================
  Files         387      387              
  Lines       96405    96405              
==========================================
- Hits        77331    76831     -500     
- Misses      19074    19574     +500     
Files with missing lines Coverage Δ
scapy/utils.py 72.03% <100.00%> (-0.05%) ⬇️

... and 22 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@polybassa polybassa merged commit dafe791 into secdev:master Jul 4, 2026
22 of 25 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.

hexdiff() raises IndexError on unequal-length inputs (difflib algorithm)

2 participants