Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
a7d89461
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a7d89461
编写于
4月 28, 2015
作者:
J
Jeffrey Wilcke
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #820 from fjl/rlp-readkind-overflow
rlp: fix list bounds check overflow (found by go-fuzz)
上级
91cb8cdd
dd49c8e4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
14 deletion
+40
-14
rlp/decode.go
rlp/decode.go
+29
-14
rlp/decode_test.go
rlp/decode_test.go
+11
-0
未找到文件。
rlp/decode.go
浏览文件 @
a7d89461
...
...
@@ -820,6 +820,16 @@ func (s *Stream) Kind() (kind Kind, size uint64, err error) {
func
(
s
*
Stream
)
readKind
()
(
kind
Kind
,
size
uint64
,
err
error
)
{
b
,
err
:=
s
.
readByte
()
if
err
!=
nil
{
if
len
(
s
.
stack
)
==
0
{
// At toplevel, Adjust the error to actual EOF. io.EOF is
// used by callers to determine when to stop decoding.
switch
err
{
case
io
.
ErrUnexpectedEOF
:
err
=
io
.
EOF
case
ErrValueTooLarge
:
err
=
io
.
EOF
}
}
return
0
,
0
,
err
}
s
.
byteval
=
0
...
...
@@ -876,9 +886,6 @@ func (s *Stream) readUint(size byte) (uint64, error) {
return
0
,
nil
case
1
:
b
,
err
:=
s
.
readByte
()
if
err
==
io
.
EOF
{
err
=
io
.
ErrUnexpectedEOF
}
return
uint64
(
b
),
err
default
:
start
:=
int
(
8
-
size
)
...
...
@@ -899,10 +906,9 @@ func (s *Stream) readUint(size byte) (uint64, error) {
}
func
(
s
*
Stream
)
readFull
(
buf
[]
byte
)
(
err
error
)
{
if
s
.
limited
&&
s
.
remaining
<
uint64
(
len
(
buf
))
{
return
ErrValueTooLarge
if
err
:=
s
.
willRead
(
uint64
(
len
(
buf
)));
err
!=
nil
{
return
err
}
s
.
willRead
(
uint64
(
len
(
buf
)))
var
nn
,
n
int
for
n
<
len
(
buf
)
&&
err
==
nil
{
nn
,
err
=
s
.
r
.
Read
(
buf
[
n
:
])
...
...
@@ -915,23 +921,32 @@ func (s *Stream) readFull(buf []byte) (err error) {
}
func
(
s
*
Stream
)
readByte
()
(
byte
,
error
)
{
if
s
.
limited
&&
s
.
remaining
==
0
{
return
0
,
io
.
EOF
if
err
:=
s
.
willRead
(
1
);
err
!=
nil
{
return
0
,
err
}
s
.
willRead
(
1
)
b
,
err
:=
s
.
r
.
ReadByte
()
if
len
(
s
.
stack
)
>
0
&&
err
==
io
.
EOF
{
if
err
==
io
.
EOF
{
err
=
io
.
ErrUnexpectedEOF
}
return
b
,
err
}
func
(
s
*
Stream
)
willRead
(
n
uint64
)
{
func
(
s
*
Stream
)
willRead
(
n
uint64
)
error
{
s
.
kind
=
-
1
// rearm Kind
if
s
.
limited
{
s
.
remaining
-=
n
}
if
len
(
s
.
stack
)
>
0
{
// check list overflow
tos
:=
s
.
stack
[
len
(
s
.
stack
)
-
1
]
if
n
>
tos
.
size
-
tos
.
pos
{
return
ErrElemTooLarge
}
s
.
stack
[
len
(
s
.
stack
)
-
1
]
.
pos
+=
n
}
if
s
.
limited
{
if
n
>
s
.
remaining
{
return
ErrValueTooLarge
}
s
.
remaining
-=
n
}
return
nil
}
rlp/decode_test.go
浏览文件 @
a7d89461
...
...
@@ -119,6 +119,10 @@ func TestStreamErrors(t *testing.T) {
{
"8158"
,
calls
{
"Uint"
,
"Uint"
},
nil
,
io
.
EOF
},
{
"C0"
,
calls
{
"List"
,
"ListEnd"
,
"List"
},
nil
,
io
.
EOF
},
{
""
,
calls
{
"List"
},
withoutInputLimit
,
io
.
EOF
},
{
"8158"
,
calls
{
"Uint"
,
"Uint"
},
withoutInputLimit
,
io
.
EOF
},
{
"C0"
,
calls
{
"List"
,
"ListEnd"
,
"List"
},
withoutInputLimit
,
io
.
EOF
},
// Input limit errors.
{
"81"
,
calls
{
"Bytes"
},
nil
,
ErrValueTooLarge
},
{
"81"
,
calls
{
"Uint"
},
nil
,
ErrValueTooLarge
},
...
...
@@ -426,6 +430,13 @@ var decodeTests = []decodeTest{
ptr
:
new
([]
io
.
Reader
),
error
:
"rlp: type io.Reader is not RLP-serializable"
,
},
// fuzzer crashes
{
input
:
"c330f9c030f93030ce3030303030303030bd303030303030"
,
ptr
:
new
(
interface
{}),
error
:
"rlp: element is larger than containing list"
,
},
}
func
uintp
(
i
uint
)
*
uint
{
return
&
i
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录