File tree 1 file changed +15
-0
lines changed
1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -83,17 +83,30 @@ impl Writer {
83
83
/// # Errors
84
84
///
85
85
/// Will return `Err` if an IO error occurs.
86
+ ///
87
+ /// # Panics
88
+ ///
89
+ /// Panics if the key length is empty or greater than 2^16, or the value length is greater than 2^32.
86
90
pub fn write ( & mut self , key : & [ u8 ] , value : & [ u8 ] ) -> std:: io:: Result < u32 > {
91
+ assert ! ( !key. is_empty( ) ) ;
92
+ assert ! ( key. len( ) <= u16 :: MAX . into( ) ) ;
93
+ assert ! ( u32 :: try_from( value. len( ) ) . is_ok( ) ) ;
94
+
87
95
#[ cfg( feature = "lz4" ) ]
88
96
let value = lz4_flex:: compress_prepend_size ( value) ;
89
97
90
98
let mut hasher = crc32fast:: Hasher :: new ( ) ;
91
99
hasher. update ( & value) ;
92
100
let crc = hasher. finalize ( ) ;
93
101
102
+ // NOTE: Truncation is okay and actually needed
103
+ #[ allow( clippy:: cast_possible_truncation) ]
94
104
self . inner . write_u16 :: < BigEndian > ( key. len ( ) as u16 ) ?;
95
105
self . inner . write_all ( key) ?;
96
106
self . inner . write_u32 :: < BigEndian > ( crc) ?;
107
+
108
+ // NOTE: Truncation is okay and actually needed
109
+ #[ allow( clippy:: cast_possible_truncation) ]
97
110
self . inner . write_u32 :: < BigEndian > ( value. len ( ) as u32 ) ?;
98
111
self . inner . write_all ( & value) ?;
99
112
@@ -112,6 +125,8 @@ impl Writer {
112
125
113
126
self . item_count += 1 ;
114
127
128
+ // NOTE: Truncation is okay
129
+ #[ allow( clippy:: cast_possible_truncation) ]
115
130
Ok ( value. len ( ) as u32 )
116
131
}
117
132
You can’t perform that action at this time.
0 commit comments