Skip to content

Images can cause crashes if the Handle is of size (0, 0) #3342

@Brogolem35

Description

@Brogolem35

Is your issue REALLY a bug?

  • My issue is indeed a bug!
  • I am not crazy! I will not fill out this form just to ask a question or request a feature. Pinky promise.

Is there an existing issue for this?

  • I have searched the existing issues.

Is this issue related to iced?

  • My hardware is compatible and my graphics drivers are up-to-date.

What happened?

use iced::{Element, widget::image};

fn main() -> iced::Result {
    iced::application(App, App::update, App::view).run()
}

struct App();

impl App {
    fn view(&self) -> Element<'_, Message> {
        let placeholder = image::Handle::from_rgba(0, 0, vec![]); // crashes
        // let placeholder = image::Handle::from_rgba(1, 1, vec![0; 4]); // does not crash
        image(placeholder).into()
    }

    fn update(&mut self, _: Message) {}
}

enum Message {}

The given program panics with the logs given below whenever it tries to render the image. It should either disallow accepting 0s as arguments (via NonZero), render an empty image or panic with a more debuggable message.

What is the expected behavior?

Empty image or a panic with a better message.

Version

master

Operating System

Linux

Do you have any log output?

https://gist.github.com/Brogolem35/8d8569c0bfea2935e3ef6678952fb652

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions