Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
4d5a518a
Commit
4d5a518a
authored
Apr 17, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rlp: stop accepting lists for byte slices and byte arrays
parent
574d5d6a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
45 deletions
+10
-45
decode.go
rlp/decode.go
+3
-11
decode_test.go
rlp/decode_test.go
+7
-34
No files found.
rlp/decode.go
View file @
4d5a518a
...
...
@@ -58,9 +58,8 @@ type Decoder interface {
// }
//
// To decode into a slice, the input must be a list and the resulting
// slice will contain the input elements in order.
// As a special case, if the slice has a byte-size element type, the input
// can also be an RLP string.
// slice will contain the input elements in order. For byte slices,
// the input must be an RLP string.
//
// To decode into a Go string, the input must be an RLP string. The
// input bytes are taken as-is and will not necessarily be valid UTF-8.
...
...
@@ -309,13 +308,6 @@ func decodeListArray(s *Stream, val reflect.Value, elemdec decoder) error {
}
func
decodeByteSlice
(
s
*
Stream
,
val
reflect
.
Value
)
error
{
kind
,
_
,
err
:=
s
.
Kind
()
if
err
!=
nil
{
return
err
}
if
kind
==
List
{
return
decodeListSlice
(
s
,
val
,
decodeUint
)
}
b
,
err
:=
s
.
Bytes
()
if
err
!=
nil
{
return
wrapStreamError
(
err
,
val
.
Type
())
...
...
@@ -351,7 +343,7 @@ func decodeByteArray(s *Stream, val reflect.Value) error {
return
wrapStreamError
(
ErrCanonSize
,
val
.
Type
())
}
case
List
:
return
decodeListArray
(
s
,
val
,
decodeUint
)
return
wrapStreamError
(
ErrExpectedString
,
val
.
Type
()
)
}
return
nil
}
...
...
rlp/decode_test.go
View file @
4d5a518a
...
...
@@ -323,56 +323,29 @@ var decodeTests = []decodeTest{
// byte slices
{
input
:
"01"
,
ptr
:
new
([]
byte
),
value
:
[]
byte
{
1
}},
{
input
:
"80"
,
ptr
:
new
([]
byte
),
value
:
[]
byte
{}},
{
input
:
"8D6162636465666768696A6B6C6D"
,
ptr
:
new
([]
byte
),
value
:
[]
byte
(
"abcdefghijklm"
)},
{
input
:
"C0"
,
ptr
:
new
([]
byte
),
value
:
[]
byte
{}},
{
input
:
"C3010203"
,
ptr
:
new
([]
byte
),
value
:
[]
byte
{
1
,
2
,
3
}},
{
input
:
"8105"
,
ptr
:
new
([]
byte
),
error
:
"rlp: non-canonical size information for []uint8"
,
},
{
input
:
"C3820102"
,
ptr
:
new
([]
byte
),
error
:
"rlp: input string too long for uint8, decoding into ([]uint8)[0]"
,
},
{
input
:
"C0"
,
ptr
:
new
([]
byte
),
error
:
"rlp: expected input string or byte for []uint8"
},
{
input
:
"8105"
,
ptr
:
new
([]
byte
),
error
:
"rlp: non-canonical size information for []uint8"
},
// byte arrays
{
input
:
"01"
,
ptr
:
new
([
5
]
byte
),
value
:
[
5
]
byte
{
1
}},
{
input
:
"80"
,
ptr
:
new
([
5
]
byte
),
value
:
[
5
]
byte
{}},
{
input
:
"850102030405"
,
ptr
:
new
([
5
]
byte
),
value
:
[
5
]
byte
{
1
,
2
,
3
,
4
,
5
}},
{
input
:
"C0"
,
ptr
:
new
([
5
]
byte
),
value
:
[
5
]
byte
{}},
{
input
:
"C3010203"
,
ptr
:
new
([
5
]
byte
),
value
:
[
5
]
byte
{
1
,
2
,
3
,
0
,
0
}},
{
input
:
"C3820102"
,
ptr
:
new
([
5
]
byte
),
error
:
"rlp: input string too long for uint8, decoding into ([5]uint8)[0]"
,
},
{
input
:
"86010203040506"
,
ptr
:
new
([
5
]
byte
),
error
:
"rlp: input string too long for [5]uint8"
,
},
{
input
:
"8105"
,
ptr
:
new
([
5
]
byte
),
error
:
"rlp: non-canonical size information for [5]uint8"
,
},
// byte array errors
{
input
:
"C0"
,
ptr
:
new
([
5
]
byte
),
error
:
"rlp: expected input string or byte for [5]uint8"
},
{
input
:
"C3010203"
,
ptr
:
new
([
5
]
byte
),
error
:
"rlp: expected input string or byte for [5]uint8"
},
{
input
:
"86010203040506"
,
ptr
:
new
([
5
]
byte
),
error
:
"rlp: input string too long for [5]uint8"
},
{
input
:
"8105"
,
ptr
:
new
([
5
]
byte
),
error
:
"rlp: non-canonical size information for [5]uint8"
},
// byte array reuse (should be zeroed)
{
input
:
"850102030405"
,
ptr
:
&
sharedByteArray
,
value
:
[
5
]
byte
{
1
,
2
,
3
,
4
,
5
}},
{
input
:
"01"
,
ptr
:
&
sharedByteArray
,
value
:
[
5
]
byte
{
1
}},
// kind: String
{
input
:
"850102030405"
,
ptr
:
&
sharedByteArray
,
value
:
[
5
]
byte
{
1
,
2
,
3
,
4
,
5
}},
{
input
:
"01"
,
ptr
:
&
sharedByteArray
,
value
:
[
5
]
byte
{
1
}},
// kind: Byte
{
input
:
"C3010203"
,
ptr
:
&
sharedByteArray
,
value
:
[
5
]
byte
{
1
,
2
,
3
,
0
,
0
}},
{
input
:
"C101"
,
ptr
:
&
sharedByteArray
,
value
:
[
5
]
byte
{
1
}},
// kind: List
// zero sized byte arrays
{
input
:
"80"
,
ptr
:
new
([
0
]
byte
),
value
:
[
0
]
byte
{}},
{
input
:
"C0"
,
ptr
:
new
([
0
]
byte
),
value
:
[
0
]
byte
{}},
{
input
:
"01"
,
ptr
:
new
([
0
]
byte
),
error
:
"rlp: input string too long for [0]uint8"
},
{
input
:
"8101"
,
ptr
:
new
([
0
]
byte
),
error
:
"rlp: input string too long for [0]uint8"
},
...
...
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