Skip to content

Commit

Permalink
Don't attempt to append zero length fragments
Browse files Browse the repository at this point in the history
Before the fragmentBuffer would process zero length fragments. Since
they are zero length the append would not do anything. This would
result in an infinite loop.
  • Loading branch information
Sean-Der committed May 10, 2022
1 parent ba1a176 commit e0b2ce3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fragment_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (f *fragmentBuffer) pop() (content []byte, epoch uint16) {
for _, f := range frags {
if f.handshakeHeader.FragmentOffset == targetOffset {
fragmentEnd := (f.handshakeHeader.FragmentOffset + f.handshakeHeader.FragmentLength)
if fragmentEnd != f.handshakeHeader.Length {
if fragmentEnd != f.handshakeHeader.Length && f.handshakeHeader.FragmentLength != 0 {
if !appendMessage(fragmentEnd) {
return false
}
Expand Down
14 changes: 14 additions & 0 deletions fragment_buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ func TestFragmentBuffer(t *testing.T) {
},
Epoch: 0,
},
// Assert that a zero length fragment doesn't cause the fragmentBuffer to enter an infinite loop
{
Name: "Zero Length Fragment",
In: [][]byte{
{
0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
},
Expected: [][]byte{
{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00},
},
Epoch: 0,
},
} {
fragmentBuffer := newFragmentBuffer()
for _, frag := range test.In {
Expand Down

0 comments on commit e0b2ce3

Please sign in to comment.