Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
9440d823
Commit
9440d823
authored
Feb 06, 2012
by
David Symonds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gob: fuzz testing, plus a fix for very large type names.
Fixes #2689. R=r CC=golang-dev
https://golang.org/cl/5616063
parent
cee92022
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
2 deletions
+69
-2
src/pkg/encoding/gob/codec_test.go
src/pkg/encoding/gob/codec_test.go
+59
-0
src/pkg/encoding/gob/decode.go
src/pkg/encoding/gob/decode.go
+5
-1
src/pkg/encoding/gob/error.go
src/pkg/encoding/gob/error.go
+5
-1
No files found.
src/pkg/encoding/gob/codec_test.go
View file @
9440d823
...
...
@@ -8,9 +8,11 @@ import (
"bytes"
"errors"
"math"
"math/rand"
"reflect"
"strings"
"testing"
"time"
"unsafe"
)
...
...
@@ -1407,3 +1409,60 @@ func TestDebugStruct(t *testing.T) {
}
debugFunc
(
debugBuffer
)
}
func
encFuzzDec
(
rng
*
rand
.
Rand
,
in
interface
{})
error
{
buf
:=
new
(
bytes
.
Buffer
)
enc
:=
NewEncoder
(
buf
)
if
err
:=
enc
.
Encode
(
&
in
);
err
!=
nil
{
return
err
}
b
:=
buf
.
Bytes
()
for
i
,
bi
:=
range
b
{
if
rng
.
Intn
(
10
)
<
3
{
b
[
i
]
=
bi
+
uint8
(
rng
.
Intn
(
256
))
}
}
dec
:=
NewDecoder
(
buf
)
var
e
interface
{}
if
err
:=
dec
.
Decode
(
&
e
);
err
!=
nil
{
return
err
}
return
nil
}
// This does some "fuzz testing" by attempting to decode a sequence of random bytes.
func
TestFuzz
(
t
*
testing
.
T
)
{
if
testing
.
Short
()
{
return
}
// all possible inputs
input
:=
[]
interface
{}{
new
(
int
),
new
(
float32
),
new
(
float64
),
new
(
complex128
),
&
ByteStruct
{
255
},
&
ArrayStruct
{},
&
StringStruct
{
"hello"
},
&
GobTest1
{
0
,
&
StringStruct
{
"hello"
}},
}
testFuzz
(
t
,
time
.
Now
()
.
UnixNano
(),
100
,
input
...
)
}
func
TestFuzzRegressions
(
t
*
testing
.
T
)
{
// An instance triggering a type name of length ~102 GB.
testFuzz
(
t
,
1328492090837718000
,
100
,
new
(
float32
))
}
func
testFuzz
(
t
*
testing
.
T
,
seed
int64
,
n
int
,
input
...
interface
{})
{
t
.
Logf
(
"seed=%d n=%d
\n
"
,
seed
,
n
)
for
_
,
e
:=
range
input
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
seed
))
for
i
:=
0
;
i
<
n
;
i
++
{
encFuzzDec
(
rng
,
e
)
}
}
}
src/pkg/encoding/gob/decode.go
View file @
9440d823
...
...
@@ -690,7 +690,11 @@ func (dec *Decoder) decodeInterface(ityp reflect.Type, state *decoderState, p ui
// Create a writable interface reflect.Value. We need one even for the nil case.
ivalue
:=
allocValue
(
ityp
)
// Read the name of the concrete type.
b
:=
make
([]
byte
,
state
.
decodeUint
())
nr
:=
state
.
decodeUint
()
if
nr
<
0
||
nr
>
1
<<
31
{
// zero is permissible for anonymous types
errorf
(
"invalid type name length %d"
,
nr
)
}
b
:=
make
([]
byte
,
nr
)
state
.
b
.
Read
(
b
)
name
:=
string
(
b
)
if
name
==
""
{
...
...
src/pkg/encoding/gob/error.go
View file @
9440d823
...
...
@@ -33,7 +33,11 @@ func error_(err error) {
// plain error. It overwrites the error return of the function that deferred its call.
func
catchError
(
err
*
error
)
{
if
e
:=
recover
();
e
!=
nil
{
*
err
=
e
.
(
gobError
)
.
err
// Will re-panic if not one of our errors, such as a runtime error.
ge
,
ok
:=
e
.
(
gobError
)
if
!
ok
{
panic
(
e
)
}
*
err
=
ge
.
err
}
return
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment