File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -158,12 +158,14 @@ fn num_decimal_digits(mut n: usize) -> usize {
158
158
159
159
/// Read a document's raw BSON bytes from the provided reader.
160
160
pub ( crate ) fn read_document_bytes < R : Read > ( mut reader : R ) -> Result < Vec < u8 > > {
161
- let length = reader. read_i32_sync ( ) ?;
161
+ let length = Checked :: new ( reader. read_i32_sync ( ) ?) ;
162
162
163
- let mut bytes = Vec :: with_capacity ( length as usize ) ;
164
- bytes. write_all ( & length. to_le_bytes ( ) ) ?;
163
+ let mut bytes = Vec :: with_capacity ( length. try_into ( ) ? ) ;
164
+ bytes. write_all ( & length. try_into :: < u32 > ( ) ? . to_le_bytes ( ) ) ?;
165
165
166
- reader. take ( length as u64 - 4 ) . read_to_end ( & mut bytes) ?;
166
+ reader
167
+ . take ( ( length - 4 ) . try_into ( ) ?)
168
+ . read_to_end ( & mut bytes) ?;
167
169
168
170
Ok ( bytes)
169
171
}
You can’t perform that action at this time.
0 commit comments