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 {
158158
159159/// Read a document's raw BSON bytes from the provided reader.
160160pub ( 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 ( ) ?) ;
162162
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 ( ) ) ?;
165165
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) ?;
167169
168170 Ok ( bytes)
169171}
You can’t perform that action at this time.
0 commit comments