Skip to content

Fix IndexError/struct.error when scanning IPv6 Hop-by-Hop header for a Jumbo option - #5208

Open
AbdaullahAG wants to merge 1 commit into
secdev:masterfrom
AbdaullahAG:fix-jumbo-option-bounds
Open

AbdaullahAG wants to merge 1 commit into
secdev:masterfrom
AbdaullahAG:fix-jumbo-option-bounds

Conversation

@AbdaullahAG

Copy link
Copy Markdown

Description

IPv6.extract_padding looks for a Jumbo option in the Hop-by-Hop header with while offset <= len(data). When no Jumbo option is found and len(data) equals an offset visited by the loop, data[offset] raises IndexError. When an 0xc2 type byte is found with fewer than 6 bytes remaining, struct.unpack raises struct.error.

scapy/scapy/layers/inet6.py

Lines 366 to 370 in 7daa15d

offset = 4 * idx + 2
while offset <= len(data):
opt_type = data[offset]
if opt_type == 0xc2: # Jumbo option
jumbo_len = struct.unpack("I", data[offset + 2:offset + 2 + 4])[0] # noqa: E501

from scapy.all import IPv6

hdr = bytes(IPv6(nh=0, plen=0))
IPv6(hdr + b"\x3b\x00\x01\x00\x00\x00\x00\x00\x00\x00")  # IndexError
IPv6(hdr + b"\x3b\x00\x01\x00\x00\x00\xc2\x04\x00\x00")  # struct.error

The loop now requires 6 bytes (type, length, 4-byte value) to remain. A regression test is added to test/scapy/layers/inet6.uts.

@AbdaullahAG

Copy link
Copy Markdown
Author

@gpotter2 hi , could you please approve the workflow run for this PR so the CI checks can complete?
This is a small fix for IndexError and struct.error when parsing truncated IPv6 Hop-by-Hop headers (with regression tests included).Thanks!

@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 47.48%. Comparing base (09d4853) to head (37857eb).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
scapy/layers/inet6.py 0.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (09d4853) and HEAD (37857eb). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (09d4853) HEAD (37857eb)
3 2
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #5208       +/-   ##
===========================================
- Coverage   78.59%   47.48%   -31.12%     
===========================================
  Files         375      375               
  Lines       98482    98482               
===========================================
- Hits        77403    46763    -30640     
- Misses      21079    51719    +30640     
Files with missing lines Coverage Δ
scapy/layers/inet6.py 41.13% <0.00%> (-47.55%) ⬇️

... and 282 files with indirect coverage changes

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

Fix an out-of-bounds read when parsing IPv6 options where an Option 194 (Jumbo Payload) payload is shorter than expected.

AI-Assisted: yes (to find the bug, code written manually)
@gpotter2
gpotter2 force-pushed the fix-jumbo-option-bounds branch from 1e0519f to 37857eb Compare November 11, 2026 17:13
@gpotter2
gpotter2 enabled auto-merge (squash) November 11, 2026 17:14
@gpotter2

Copy link
Copy Markdown
Member

Thanks for the PR ! sadly tests don't pass.

@gpotter2
gpotter2 disabled auto-merge November 11, 2026 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants