mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-03 13:00:37 +08:00
godep: update go-msgio
This commit is contained in:
2
Godeps/Godeps.json
generated
2
Godeps/Godeps.json
generated
@ -169,7 +169,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/jbenet/go-msgio",
|
"ImportPath": "github.com/jbenet/go-msgio",
|
||||||
"Rev": "dbae89193876910c736b2ce1291fa8bbcf299d77"
|
"Rev": "b4f3f1e1c7ec0cbf2fe35d8a45d1c253d224dc72"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/jbenet/go-multiaddr",
|
"ImportPath": "github.com/jbenet/go-multiaddr",
|
||||||
|
9
Godeps/_workspace/src/github.com/jbenet/go-msgio/.travis.yml
generated
vendored
Normal file
9
Godeps/_workspace/src/github.com/jbenet/go-msgio/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
language: go
|
||||||
|
|
||||||
|
go:
|
||||||
|
- 1.3
|
||||||
|
- 1.4
|
||||||
|
- release
|
||||||
|
|
||||||
|
script:
|
||||||
|
- go test -race -cpu=5 -v ./...
|
23
Godeps/_workspace/src/github.com/jbenet/go-msgio/fuzz.go
generated
vendored
Normal file
23
Godeps/_workspace/src/github.com/jbenet/go-msgio/fuzz.go
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// +build gofuzz
|
||||||
|
|
||||||
|
package msgio
|
||||||
|
|
||||||
|
import "bytes"
|
||||||
|
|
||||||
|
// get the go-fuzz tools and build a fuzzer
|
||||||
|
// $ go get -u github.com/dvyukov/go-fuzz/...
|
||||||
|
// $ go-fuzz-build github.com/jbenet/go-msgio
|
||||||
|
|
||||||
|
// put a corpus of random (even better if actual, structured) data in a corpus directry
|
||||||
|
// $ go-fuzz -bin ./msgio-fuzz -corpus corpus -workdir=wdir -timeout=15
|
||||||
|
|
||||||
|
func Fuzz(data []byte) int {
|
||||||
|
rc := NewReader(bytes.NewReader(data))
|
||||||
|
// rc := NewVarintReader(bytes.NewReader(data))
|
||||||
|
|
||||||
|
if _, err := rc.ReadMsg(); err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
24
Godeps/_workspace/src/github.com/jbenet/go-msgio/fuzz_test.go
generated
vendored
Normal file
24
Godeps/_workspace/src/github.com/jbenet/go-msgio/fuzz_test.go
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package msgio
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestReader_CrashOne(t *testing.T) {
|
||||||
|
rc := NewReader(strings.NewReader("\x83000"))
|
||||||
|
_, err := rc.ReadMsg()
|
||||||
|
if err != ErrMsgTooLarge {
|
||||||
|
t.Error("should get ErrMsgTooLarge")
|
||||||
|
t.Log(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestVarintReader_CrashOne(t *testing.T) {
|
||||||
|
rc := NewVarintReader(strings.NewReader("\x9a\xf1\xed\x9a0"))
|
||||||
|
_, err := rc.ReadMsg()
|
||||||
|
if err != ErrMsgTooLarge {
|
||||||
|
t.Error("should get ErrMsgTooLarge")
|
||||||
|
t.Log(err)
|
||||||
|
}
|
||||||
|
}
|
15
Godeps/_workspace/src/github.com/jbenet/go-msgio/msgio.go
generated
vendored
15
Godeps/_workspace/src/github.com/jbenet/go-msgio/msgio.go
generated
vendored
@ -2,6 +2,7 @@ package msgio
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -11,7 +12,13 @@ import (
|
|||||||
// NBO is NetworkByteOrder
|
// NBO is NetworkByteOrder
|
||||||
var NBO = binary.BigEndian
|
var NBO = binary.BigEndian
|
||||||
|
|
||||||
const lengthSize = 4
|
// ErrMsgTooLarge is returned when the message length is exessive
|
||||||
|
var ErrMsgTooLarge = errors.New("message too large")
|
||||||
|
|
||||||
|
const (
|
||||||
|
lengthSize = 4
|
||||||
|
defaultMaxSize = 8 * 1024 * 1024 // 8mb
|
||||||
|
)
|
||||||
|
|
||||||
// Writer is the msgio Writer interface. It writes len-framed messages.
|
// Writer is the msgio Writer interface. It writes len-framed messages.
|
||||||
type Writer interface {
|
type Writer interface {
|
||||||
@ -121,6 +128,7 @@ type reader struct {
|
|||||||
next int
|
next int
|
||||||
pool *mpool.Pool
|
pool *mpool.Pool
|
||||||
lock sync.Locker
|
lock sync.Locker
|
||||||
|
max int // the maximal message size (in bytes) this reader handles
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewReader wraps an io.Reader with a msgio framed reader. The msgio.Reader
|
// NewReader wraps an io.Reader with a msgio framed reader. The msgio.Reader
|
||||||
@ -143,6 +151,7 @@ func NewReaderWithPool(r io.Reader, p *mpool.Pool) ReadCloser {
|
|||||||
next: -1,
|
next: -1,
|
||||||
pool: p,
|
pool: p,
|
||||||
lock: new(sync.Mutex),
|
lock: new(sync.Mutex),
|
||||||
|
max: defaultMaxSize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,6 +200,10 @@ func (s *reader) ReadMsg() ([]byte, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if length > s.max {
|
||||||
|
return nil, ErrMsgTooLarge
|
||||||
|
}
|
||||||
|
|
||||||
msgb := s.pool.Get(uint32(length))
|
msgb := s.pool.Get(uint32(length))
|
||||||
if msgb == nil {
|
if msgb == nil {
|
||||||
return nil, io.ErrShortBuffer
|
return nil, io.ErrShortBuffer
|
||||||
|
6
Godeps/_workspace/src/github.com/jbenet/go-msgio/varint.go
generated
vendored
6
Godeps/_workspace/src/github.com/jbenet/go-msgio/varint.go
generated
vendored
@ -67,6 +67,7 @@ type varintReader struct {
|
|||||||
next int
|
next int
|
||||||
pool *mpool.Pool
|
pool *mpool.Pool
|
||||||
lock sync.Locker
|
lock sync.Locker
|
||||||
|
max int // the maximal message size (in bytes) this reader handles
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewVarintReader wraps an io.Reader with a varint msgio framed reader.
|
// NewVarintReader wraps an io.Reader with a varint msgio framed reader.
|
||||||
@ -92,6 +93,7 @@ func NewVarintReaderWithPool(r io.Reader, p *mpool.Pool) ReadCloser {
|
|||||||
next: -1,
|
next: -1,
|
||||||
pool: p,
|
pool: p,
|
||||||
lock: new(sync.Mutex),
|
lock: new(sync.Mutex),
|
||||||
|
max: defaultMaxSize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,6 +143,10 @@ func (s *varintReader) ReadMsg() ([]byte, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if length > s.max {
|
||||||
|
return nil, ErrMsgTooLarge
|
||||||
|
}
|
||||||
|
|
||||||
msgb := s.pool.Get(uint32(length))
|
msgb := s.pool.Get(uint32(length))
|
||||||
if msgb == nil {
|
if msgb == nil {
|
||||||
return nil, io.ErrShortBuffer
|
return nil, io.ErrShortBuffer
|
||||||
|
Reference in New Issue
Block a user