Skip to content

Commit 2c533ef

Browse files
committed
auto merge of #19799 : alexcrichton/rust/stop-panicking, r=huonw
Fix a panic where the compiler was looking at stale or old metadata. See #19798, #19772, #19757, #19744, #19718, #19691.
2 parents 4e8ba49 + 9a47d65 commit 2c533ef

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/librustc/metadata/cstore.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,17 @@ impl MetadataBlob {
238238
MetadataArchive(ref ar) => ar.as_slice(),
239239
};
240240
if slice.len() < 4 {
241-
&[]
241+
&[] // corrupt metadata
242242
} else {
243-
let len = ((slice[0] as u32) << 24) |
244-
((slice[1] as u32) << 16) |
245-
((slice[2] as u32) << 8) |
246-
((slice[3] as u32) << 0);
247-
slice.slice(4, len as uint + 4)
243+
let len = (((slice[0] as u32) << 24) |
244+
((slice[1] as u32) << 16) |
245+
((slice[2] as u32) << 8) |
246+
((slice[3] as u32) << 0)) as uint;
247+
if len + 4 <= slice.len() {
248+
slice.slice(4, len + 4)
249+
} else {
250+
&[] // corrupt or old metadata
251+
}
248252
}
249253
}
250254
}

0 commit comments

Comments
 (0)