Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
rustc: Don't panic on corrupt metadata
Fix a panic where the compiler was looking at stale or old metadata.

See #19798, #19772, #19757, #19744, #19718, #19691.
  • Loading branch information
alexcrichton committed Dec 13, 2014
1 parent ffc1118 commit 9a47d65
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/librustc/metadata/cstore.rs
Expand Up @@ -236,13 +236,17 @@ impl MetadataBlob {
MetadataArchive(ref ar) => ar.as_slice(),
};
if slice.len() < 4 {
&[]
&[] // corrupt metadata
} 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)
let len = (((slice[0] as u32) << 24) |
((slice[1] as u32) << 16) |
((slice[2] as u32) << 8) |
((slice[3] as u32) << 0)) as uint;
if len + 4 <= slice.len() {
slice.slice(4, len + 4)
} else {
&[] // corrupt or old metadata
}
}
}
}

5 comments on commit 9a47d65

@huonw
Copy link
Member

@huonw huonw commented on 9a47d65 Dec 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

@bors
Copy link
Contributor

@bors bors commented on 9a47d65 Dec 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from huonw
at alexcrichton@9a47d65

@bors
Copy link
Contributor

@bors bors commented on 9a47d65 Dec 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/stop-panicking = 9a47d65 into auto

@bors
Copy link
Contributor

@bors bors commented on 9a47d65 Dec 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status: {"merge_sha": "2c533efd090e709a682468813aff36c368fdcd9d"}

@bors
Copy link
Contributor

@bors bors commented on 9a47d65 Dec 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/stop-panicking = 9a47d65 merged ok, testing candidate = 2c533ef

Please sign in to comment.