File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,9 @@ func (fe *LengthFieldBasedFrameExtractor) ExtractFrame(bytes []byte) ([]byte, bo
3232 return fe .handleNewFrame (bytes )
3333 }
3434 if fe .readyForNextFrame && fe .frameBuffer .Len () != 0 {
35+ if fe .frameBuffer .Len ()< 4 {
36+ log .Fatal ("wtf:" + hex .Dump (fe .frameBuffer .Bytes ()))
37+ }
3538 fe .nextFrameSize = int (binary .LittleEndian .Uint32 (fe .frameBuffer .Next (4 ))) - 4
3639 fe .readyForNextFrame = false
3740 return fe .ExtractFrame (bytes )
@@ -50,6 +53,11 @@ func (fe *LengthFieldBasedFrameExtractor) ExtractFrame(bytes []byte) ([]byte, bo
5053}
5154
5255func (fe * LengthFieldBasedFrameExtractor ) handleNewFrame (bytes []byte ) ([]byte , bool ) {
56+ //ZeroLengthPackages are sometimes sent on USB Connections. It is safe to ignore them.
57+ if len (bytes ) == 0 {
58+ log .Debugf ("skipping 0" )
59+ return nil , false
60+ }
5361 if len (bytes ) < 4 {
5462 log .Fatalf ("Received less than four bytes, cannot read a valid frameLength field: %s" , hex .Dump (bytes ))
5563 }
@@ -66,4 +74,4 @@ func (fe *LengthFieldBasedFrameExtractor) handleNewFrame(bytes []byte) ([]byte,
6674 fe .frameBuffer .Write (bytes [4 :])
6775 fe .nextFrameSize = frameLength - 4
6876 return nil , false
69- }
77+ }
Original file line number Diff line number Diff line change @@ -18,6 +18,13 @@ func TestCompletePacket(t *testing.T) {
1818 frame1 , frameReturned2 := fe .ExtractFrame (small )
1919 assert .True (t , frameReturned2 )
2020 assert .Equal (t , small [4 :], frame1 )
21+
22+ }
23+
24+ func TestZeroLengthPacket (t * testing.T ) {
25+ fe := screencapture .NewLengthFieldBasedFrameExtractor ()
26+ _ , frameReturned := fe .ExtractFrame (make ([]byte , 0 ))
27+ assert .False (t , frameReturned )
2128}
2229
2330func TestIncompletePacket (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments