@@ -136,10 +136,12 @@ impl<'a> fmt::Display for Rlp<'a> {
136
136
Ok ( Prototype :: Data ( _) ) => write ! ( f, "\" 0x{}\" " , self . data( ) . unwrap( ) . to_hex( ) ) ,
137
137
Ok ( Prototype :: List ( len) ) => {
138
138
write ! ( f, "[" ) ?;
139
- for i in 0 ..len - 1 {
140
- write ! ( f, "{}, " , self . at( i) . unwrap( ) ) ?;
139
+ if len > 0 {
140
+ for i in 0 ..len - 1 {
141
+ write ! ( f, "{}, " , self . at( i) . unwrap( ) ) ?;
142
+ }
143
+ write ! ( f, "{}" , self . at( len - 1 ) . unwrap( ) ) ?;
141
144
}
142
- write ! ( f, "{}" , self . at( len - 1 ) . unwrap( ) ) ?;
143
145
write ! ( f, "]" )
144
146
}
145
147
Err ( err) => write ! ( f, "{:?}" , err) ,
@@ -221,6 +223,19 @@ where
221
223
// skip up to x items
222
224
bytes = Rlp :: consume_items ( bytes, to_skip) ?;
223
225
226
+ let payload_info = self . payload_info ( ) ?;
227
+ let offset_max = payload_info. header_len + payload_info. value_len - 1 ;
228
+ let new_offset = self . bytes . len ( ) - bytes. len ( ) ;
229
+ // self.data.len() can be greater than byte length from payload's length
230
+ // But you should not read the data which is lied after payload's length
231
+ if new_offset > offset_max {
232
+ return Err ( DecoderError :: RlpIsTooShort {
233
+ expected : new_offset,
234
+ got : offset_max,
235
+ } )
236
+ }
237
+
238
+
224
239
// update the cache
225
240
self . offset_cache . set ( OffsetCache :: new ( index, self . bytes . len ( ) - bytes. len ( ) ) ) ;
226
241
0 commit comments