Cover a couple of more cases on data track runt packet handling. (#4741)

* Cover a couple of more cases on data track runt packet handling.

* Guard data track header parser against extensions-size integer wraparound.

Widen the extensions-size arithmetic to int so a 0xFFFF wire value no
longer wraps in uint16, and reject any packet whose computed hdrSize
exceeds the buffer before slicing the payload.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Raja Subramanian
2026-08-11 18:25:10 +05:30
committed by GitHub
co-authored by Claude Opus 4.8
parent d279899b7c
commit c4c356f6ca
2 changed files with 47 additions and 3 deletions
+35
View File
@@ -256,4 +256,39 @@ func TestPacket(t *testing.T) {
err = unmarshaled.Unmarshal(badPacket)
require.Error(t, err)
})
t.Run("oversized extension padding does not panic", func(t *testing.T) {
var unmarshaled Packet
// HasExtensions set, extensionsSize describes more bytes than present,
// terminated by a 0x00 padding id -> hdrSize would exceed len(buf)
badPacket := []byte{
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}
err := unmarshaled.Unmarshal(badPacket)
require.Error(t, err)
})
t.Run("extensions size wraparound does not panic", func(t *testing.T) {
var unmarshaled Packet
// 0xFFFF extensions-size field wraps (raw+1)*4 uint16 arithmetic to a huge
// remainingSize; the 0x00 padding id must not push hdrSize past len(buf)
badPacket := []byte{
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00,
}
err := unmarshaled.Unmarshal(badPacket)
require.Error(t, err)
})
t.Run("truncated extensions size field does not panic", func(t *testing.T) {
var unmarshaled Packet
// HasExtensions set but buffer too short to hold the extensionsSize field
badPacket := []byte{
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00,
}
err := unmarshaled.Unmarshal(badPacket)
require.Error(t, err)
})
}