1
Fork 0

Rollup merge of #75146 - tmiasko:range-overflow, r=Mark-Simulacrum

Detect overflow in proc_macro_server subspan

* Detect overflow in proc_macro_server subspan
* Add tests for overflow in Vec::drain
* Add tests for overflow in String / VecDeque operations using ranges
This commit is contained in:
Dylan DPC 2020-09-16 01:30:30 +02:00 committed by GitHub
commit fb9bb2b5ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 2 deletions

View file

@ -3,6 +3,7 @@ use std::collections::TryReserveError::*;
use std::fmt::Debug;
use std::iter::InPlaceIterable;
use std::mem::size_of;
use std::ops::Bound::*;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::rc::Rc;
use std::vec::{Drain, IntoIter};
@ -645,6 +646,16 @@ fn test_drain_max_vec_size() {
assert_eq!(v.len(), usize::MAX - 1);
}
#[test]
#[should_panic]
fn test_drain_index_overflow() {
let mut v = Vec::<()>::with_capacity(usize::MAX);
unsafe {
v.set_len(usize::MAX);
}
v.drain(0..=usize::MAX);
}
#[test]
#[should_panic]
fn test_drain_inclusive_out_of_bounds() {
@ -652,6 +663,20 @@ fn test_drain_inclusive_out_of_bounds() {
v.drain(5..=5);
}
#[test]
#[should_panic]
fn test_drain_start_overflow() {
let mut v = vec![1, 2, 3];
v.drain((Excluded(usize::MAX), Included(0)));
}
#[test]
#[should_panic]
fn test_drain_end_overflow() {
let mut v = vec![1, 2, 3];
v.drain((Included(0), Included(usize::MAX)));
}
#[test]
fn test_drain_leak() {
static mut DROPS: i32 = 0;