File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,12 @@ pub enum Error {
25
25
/// The associated byte sequence does not correspond to a valid Roughtime tag.
26
26
InvalidTag ( Box < [ u8 ] > ) ,
27
27
28
+ /// Invalid number of tags specified
29
+ InvalidNumTags ( u32 ) ,
30
+
31
+ /// Tag value length exceeds length of source bytes
32
+ InvalidValueLength ( Tag , u32 ) ,
33
+
28
34
/// Encoding failed. The associated `std::io::Error` should provide more information.
29
35
EncodingFailure ( std:: io:: Error ) ,
30
36
@@ -37,9 +43,6 @@ pub enum Error {
37
43
/// Offset is outside of valid message range
38
44
InvalidOffsetValue ( u32 ) ,
39
45
40
- /// Invalid number of tags specified
41
- InvalidNumTags ( u32 ) ,
42
-
43
46
/// Could not convert bytes to message because bytes were too short
44
47
MessageTooShort ,
45
48
Original file line number Diff line number Diff line change @@ -112,14 +112,19 @@ impl RtMessage {
112
112
// as an offset from the end of the header
113
113
let msg_end = bytes. len ( ) - header_end;
114
114
115
- assert_eq ! ( offsets. len( ) , tags. len( ) - 1 ) ;
116
-
117
115
for ( tag, ( value_start, value_end) ) in tags. into_iter ( ) . zip (
118
116
once ( & 0 )
119
117
. chain ( offsets. iter ( ) )
120
- . zip ( offsets. iter ( ) . chain ( once ( & msg_end) ) ) ,
118
+ . zip ( offsets. iter ( ) . chain ( once ( & msg_end) ) )
121
119
) {
122
- let value = bytes[ ( header_end + value_start) ..( header_end + value_end) ] . to_vec ( ) ;
120
+ let start_idx = header_end + value_start;
121
+ let end_idx = header_end + value_end;
122
+
123
+ if end_idx > msg_end || start_idx > end_idx {
124
+ return Err ( Error :: InvalidValueLength ( tag, end_idx as u32 ) ) ;
125
+ }
126
+
127
+ let value = bytes[ start_idx..end_idx] . to_vec ( ) ;
123
128
rt_msg. add_field ( tag, & value) ?;
124
129
}
125
130
You can’t perform that action at this time.
0 commit comments