Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some arithmetic overflow bugs found by libfuzzer #537

Open
kuzeyardabulut opened this issue Aug 7, 2023 · 1 comment
Open

Some arithmetic overflow bugs found by libfuzzer #537

kuzeyardabulut opened this issue Aug 7, 2023 · 1 comment

Comments

@kuzeyardabulut
Copy link

Hi,
I've using libfuzzer to fuzz this crate. And I've found 2 API may panic due to arithmetic overflow.

Issue Description

We are getting crashes in adaptive_threshold function. The following code blocks triggers integer overflow.

current.channels_mut()[c as usize] = above.channels()[c as usize] + sum[c as usize];

[lhs[0] + rhs[0]]

Reproduction

Below is an example program that triggers an integer overflow. Simply calling imageproc::contrast::adaptive_threshold with specific image files triggers this vulnerability.

PoC

You can test both vulnerabilities by following the guide below.

Code:

use imageproc::contrast::adaptive_threshold;
use std::fs::read;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let file_path = "png_name";

    let buffer = read(file_path)?;

    let img = image::load_from_memory(&buffer)?;

    let rgb_image = img.to_luma8();

    let _ = adaptive_threshold(&rgb_image, 10);

    println!("Done.");
    Ok(())
}

first#174.png -> This input will trigger this vulnerable code block:

[lhs[0] + rhs[0]]

image

second#142.png -> This input will trigger this vulnerable code block:

current.channels_mut()[c as usize] = above.channels()[c as usize] + sum[c as usize];

image

@cospectrum
Copy link
Contributor

But what we can do about it? Find edge cases and assert?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants