From be4586c1e53580cb213ae3b3e2ea099b564107e4 Mon Sep 17 00:00:00 2001 From: Radzivon Bartoshyk Date: Thu, 5 Dec 2024 12:21:23 +0000 Subject: [PATCH] Fuzzing YUV400, No response --- .github/workflows/no-response.yml | 3 ++ fuzz/Cargo.toml | 7 +++ fuzz/y_to_rgb/y_to_rgb.rs | 73 +++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 fuzz/y_to_rgb/y_to_rgb.rs diff --git a/.github/workflows/no-response.yml b/.github/workflows/no-response.yml index a4b4351d..fc5cbc5d 100644 --- a/.github/workflows/no-response.yml +++ b/.github/workflows/no-response.yml @@ -7,6 +7,9 @@ on: jobs: noResponse: + permissions: + issues: write + pull-requests: write runs-on: ubuntu-latest steps: - uses: actions/stale@v9 diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 08573121..0e0bf46c 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -24,3 +24,10 @@ path = "yuv_nv_to_rgb/yuv_nv_to_rgb.rs" test = false doc = false bench = false + +[[bin]] +name = "y_to_rgb" +path = "y_to_rgb/y_to_rgb.rs" +test = false +doc = false +bench = false diff --git a/fuzz/y_to_rgb/y_to_rgb.rs b/fuzz/y_to_rgb/y_to_rgb.rs new file mode 100644 index 00000000..11ebd199 --- /dev/null +++ b/fuzz/y_to_rgb/y_to_rgb.rs @@ -0,0 +1,73 @@ +/* + * Copyright (c) Radzivon Bartoshyk, 12/2024. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#![no_main] +use libfuzzer_sys::fuzz_target; +use yuvutils_rs::{yuv400_to_rgb, yuv400_to_rgba, YuvGrayImage, YuvRange, YuvStandardMatrix}; + +fuzz_target!(|data: (u8, u8, u8)| { + fuzz_yuv(data.0, data.1, data.2); +}); + +fn fuzz_yuv(i_width: u8, i_height: u8, y_value: u8) { + if i_height == 0 || i_width == 0 { + return; + } + + let y_plane = vec![y_value; i_height as usize * i_width as usize]; + + let planar_image = YuvGrayImage { + y_plane: &y_plane, + y_stride: i_width as u32, + width: i_width as u32, + height: i_height as u32, + }; + + let mut target_rgb = vec![0u8; i_width as usize * i_height as usize * 3]; + + yuv400_to_rgb( + &planar_image, + &mut target_rgb, + i_width as u32 * 3, + YuvRange::Limited, + YuvStandardMatrix::Bt601, + ) + .unwrap(); + + let mut target_rgba = vec![0u8; i_width as usize * i_height as usize * 4]; + + yuv400_to_rgba( + &planar_image, + &mut target_rgba, + i_width as u32 * 4, + YuvRange::Limited, + YuvStandardMatrix::Bt601, + ) + .unwrap(); +}