auto merge of #19563 : alexcrichton/rust/issue-19501, r=pnkfelix
One of the causes of #19501 was that the metadata on OSX was getting corrupted. For any one particular invocation of the compiler the metadata file inside of an rlib archive would have extra bytes appended to the end of it. These extra bytes end up confusing rbml and have it run off the end of the array (resulting in the out of bounds detected). This commit prepends the length of metadata to the start of the metadata to ensure that we always slice the precise amount that we want, and it also un-ignores the test from #19502. Closes #19501
This commit is contained in:
commit
8fbfa66b45
@ -231,9 +231,18 @@ pub fn hash(&self) -> Svh { decoder::get_crate_hash(self.data()) }
|
||||
|
||||
impl MetadataBlob {
|
||||
pub fn as_slice<'a>(&'a self) -> &'a [u8] {
|
||||
match *self {
|
||||
let slice = match *self {
|
||||
MetadataVec(ref vec) => vec.as_slice(),
|
||||
MetadataArchive(ref ar) => ar.as_slice(),
|
||||
};
|
||||
if slice.len() < 4 {
|
||||
&[]
|
||||
} else {
|
||||
let len = ((slice[0] as u32) << 24) |
|
||||
((slice[1] as u32) << 16) |
|
||||
((slice[2] as u32) << 8) |
|
||||
((slice[3] as u32) << 0);
|
||||
slice.slice(4, len as uint + 4)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1979,7 +1979,32 @@ fn encode_dylib_dependency_formats(rbml_w: &mut Encoder, ecx: &EncodeContext) {
|
||||
pub fn encode_metadata(parms: EncodeParams, krate: &ast::Crate) -> Vec<u8> {
|
||||
let mut wr = SeekableMemWriter::new();
|
||||
encode_metadata_inner(&mut wr, parms, krate);
|
||||
wr.unwrap().into_iter().collect()
|
||||
let mut v = wr.unwrap();
|
||||
|
||||
// And here we run into yet another obscure archive bug: in which metadata
|
||||
// loaded from archives may have trailing garbage bytes. Awhile back one of
|
||||
// our tests was failing sporadially on the OSX 64-bit builders (both nopt
|
||||
// and opt) by having rbml generate an out-of-bounds panic when looking at
|
||||
// metadata.
|
||||
//
|
||||
// Upon investigation it turned out that the metadata file inside of an rlib
|
||||
// (and ar archive) was being corrupted. Some compilations would generate a
|
||||
// metadata file which would end in a few extra bytes, while other
|
||||
// compilations would not have these extra bytes appended to the end. These
|
||||
// extra bytes were interpreted by rbml as an extra tag, so they ended up
|
||||
// being interpreted causing the out-of-bounds.
|
||||
//
|
||||
// The root cause of why these extra bytes were appearing was never
|
||||
// discovered, and in the meantime the solution we're employing is to insert
|
||||
// the length of the metadata to the start of the metadata. Later on this
|
||||
// will allow us to slice the metadata to the precise length that we just
|
||||
// generated regardless of trailing bytes that end up in it.
|
||||
let len = v.len() as u32;
|
||||
v.insert(0, (len >> 0) as u8);
|
||||
v.insert(0, (len >> 8) as u8);
|
||||
v.insert(0, (len >> 16) as u8);
|
||||
v.insert(0, (len >> 24) as u8);
|
||||
return v;
|
||||
}
|
||||
|
||||
fn encode_metadata_inner(wr: &mut SeekableMemWriter,
|
||||
|
@ -11,7 +11,6 @@
|
||||
// aux-build:issue-13560-1.rs
|
||||
// aux-build:issue-13560-2.rs
|
||||
// aux-build:issue-13560-3.rs
|
||||
// ignore-pretty FIXME #19501
|
||||
// ignore-stage1
|
||||
|
||||
// Regression test for issue #13560, the test itself is all in the dependent
|
||||
|
Loading…
Reference in New Issue
Block a user