1Password / arboard

A clipboard for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong data after `clipboard.get_image()`

martinellison opened this issue · comments

I'm getting image data that is completely wrong in size (and presumably in format) when I copy random internet images to the clipboard and then call get_image() .

I am assuming that, given something like let x = clipboard.get_image()?, then we should have x.bytes.len() == 4 * x.width * x.height. But I am not getting that at all.

Please advise.

Hey thanks for opening an issue.

Yes your assumption is correct, so this seems like a bug. Which operating system are you experiencing this on?

I'm confused. If x.bytes.len() == 4 * x.width * x.height fails to be true, then the solution posted to reddit shouldn't work either as far as I understand. Unfortunately I cannot test on Linux right now but if you could provide a minial example that reproduces the incorrect behaviour along with an image for which this happens, I'd be delighted.

I'm a bit confused too: my example program works, even for the image that caused the error that I reported,

I'll see if I can find an image that triggers the error; I have restored the check on image length back into the code of my original program.

Here, for what it is worth, is my example program:

/** example for testing clipboard */
use anyhow::{ensure, Result};
use arboard::Clipboard;
fn main() {
    if let Err(e) = main_inner() {
        eprintln!("Image error: {:?}", &e);
    };
}

/// actually run everything
fn main_inner() -> Result<()> {
    let mut clipboard = Clipboard::new()?;
    let image = clipboard.get_image()?;
    let expected = image.width * image.height * 4;
    eprintln!(
        "\ngot {}×{} image, length {} bytes (expected {})",
        &image.width,
        &image.height,
        image.bytes.len(),
        &expected
    );
    ensure!(expected == image.bytes.len());
    Ok(())
}

I'm going to close this for now, but this should be reopened if we find evidence that this is indeed a bug in this crate.