1 // Copyright 2021, The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #![allow(missing_docs)] 16 #![no_main] 17 #[macro_use] extern crate libfuzzer_sys; 18 heap_oob()19fn heap_oob() { 20 let xs = vec![0, 1, 2, 3]; 21 let val = unsafe { *xs.as_ptr().offset(4) }; 22 println!("Out-of-bounds heap value: {}", val); 23 } 24 25 fuzz_target!(|data: &[u8]| { 26 let magic_number = 327; 27 if data.len() == magic_number { 28 heap_oob(); 29 } 30 }); 31