From abd408433f1e95423bcf536d789bb29cda4e012c Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Wed, 27 Sep 2017 23:20:47 -0700 Subject: [PATCH] Add a testing API. This will allow us to verify the entire detection pipeline in real nightly builds, which will give us confidence that real heap corruption will be detected and reported properly. MozReview-Commit-ID: 43Fp2HT8RYy --- components/style/stylist.rs | 11 +++++++++++ ports/geckolib/glue.rs | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 0b0b020cf19..47dfcad1aa5 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -1508,6 +1508,17 @@ impl Stylist { pub fn shutdown() { UA_CASCADE_DATA_CACHE.lock().unwrap().clear() } + + /// Temporary testing method. See bug 1403397. + pub fn corrupt_rule_hash_and_crash(&self, index: usize) { + let mut origin_iter = self.cascade_data.iter_origins(); + let d = origin_iter.next().unwrap().0; + let mut it = d.element_map.local_name_hash.iter(); + let nth = index % it.len(); + let entry = it.nth(nth).unwrap(); + let ptr = entry.0 as *const _ as *const usize as *mut usize; + unsafe { *ptr = 0; } + } } /// This struct holds data which users of Stylist may want to extract diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index d79b2ca6496..432ed4a73c6 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -4046,3 +4046,9 @@ pub extern "C" fn Servo_HasPendingRestyleAncestor(element: RawGeckoElementBorrow } false } + +#[no_mangle] +pub extern "C" fn Servo_CorruptRuleHashAndCrash(set: RawServoStyleSetBorrowed, index: usize) { + let per_doc_data = PerDocumentStyleData::from_ffi(set).borrow(); + per_doc_data.stylist.corrupt_rule_hash_and_crash(index); +}