@@ -123,9 +123,8 @@ pub fn read_version(dylib_path: &AbsPath) -> io::Result<String> {
123
123
let version = u32:: from_be_bytes ( [ dot_rustc[ 4 ] , dot_rustc[ 5 ] , dot_rustc[ 6 ] , dot_rustc[ 7 ] ] ) ;
124
124
// Last supported version is:
125
125
// https://github.com/rust-lang/rust/commit/b94cfefc860715fb2adf72a6955423d384c69318
126
- let ( snappy_portion, bytes_before_version) = match version {
127
- 5 | 6 => ( & dot_rustc[ 8 ..] , 13 ) ,
128
- 7 | 8 => {
126
+ let ( mut metadata_portion, bytes_before_version) = match version {
127
+ 8 => {
129
128
let len_bytes = & dot_rustc[ 8 ..12 ] ;
130
129
let data_len = u32:: from_be_bytes ( len_bytes. try_into ( ) . unwrap ( ) ) as usize ;
131
130
( & dot_rustc[ 12 ..data_len + 12 ] , 13 )
@@ -143,25 +142,18 @@ pub fn read_version(dylib_path: &AbsPath) -> io::Result<String> {
143
142
}
144
143
} ;
145
144
146
- let mut uncompressed: Box < dyn Read > = if & snappy_portion[ 0 ..4 ] == b"rust" {
147
- // Not compressed.
148
- Box :: new ( snappy_portion)
149
- } else {
150
- Box :: new ( SnapDecoder :: new ( snappy_portion) )
151
- } ;
152
-
153
145
// We're going to skip over the bytes before the version string, so basically:
154
146
// 8 bytes for [b'r',b'u',b's',b't',0,0,0,5]
155
147
// 4 or 8 bytes for [crate root bytes]
156
148
// 1 byte for length of version string
157
149
// so 13 or 17 bytes in total, and we should check the last of those bytes
158
150
// to know the length
159
151
let mut bytes = [ 0u8 ; 17 ] ;
160
- uncompressed . read_exact ( & mut bytes[ ..bytes_before_version] ) ?;
152
+ metadata_portion . read_exact ( & mut bytes[ ..bytes_before_version] ) ?;
161
153
let length = bytes[ bytes_before_version - 1 ] ;
162
154
163
155
let mut version_string_utf8 = vec ! [ 0u8 ; length as usize ] ;
164
- uncompressed . read_exact ( & mut version_string_utf8) ?;
156
+ metadata_portion . read_exact ( & mut version_string_utf8) ?;
165
157
let version_string = String :: from_utf8 ( version_string_utf8) ;
166
158
version_string. map_err ( |e| io:: Error :: new ( io:: ErrorKind :: InvalidData , e) )
167
159
}
0 commit comments