File tree 1 file changed +4
-6
lines changed 1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ use bitcoin::network::serialize::{deserialize,serialize};
5
5
use bitcoin:: blockdata:: script:: Script ;
6
6
7
7
use std:: error:: Error ;
8
- use std:: fmt;
8
+ use std:: { cmp , fmt} ;
9
9
use std:: result:: Result ;
10
10
11
11
use util:: { byte_utils, internal_traits, events} ;
@@ -1626,11 +1626,9 @@ impl MsgDecodable for ErrorMessage {
1626
1626
if v. len ( ) < 34 {
1627
1627
return Err ( DecodeError :: ShortRead ) ;
1628
1628
}
1629
- let len = byte_utils:: slice_to_be16 ( & v[ 32 ..34 ] ) ;
1630
- if v. len ( ) < 34 + len as usize {
1631
- return Err ( DecodeError :: ShortRead ) ;
1632
- }
1633
- let data = match String :: from_utf8 ( v[ 34 ..34 + len as usize ] . to_vec ( ) ) {
1629
+ // Unlike most messages, BOLT 1 requires we truncate our read if the value is out of range
1630
+ let mut len = cmp:: min ( byte_utils:: slice_to_be16 ( & v[ 32 ..34 ] ) as usize , v. len ( ) - 34 ) ;
1631
+ let data = match String :: from_utf8 ( v[ 34 ..34 + len] . to_vec ( ) ) {
1634
1632
Ok ( s) => s,
1635
1633
Err ( _) => return Err ( DecodeError :: BadText ) ,
1636
1634
} ;
You can’t perform that action at this time.
0 commit comments