Skip to content

Grid.decode() returns InvalidVersion for valid QR codes with high versions #2

@danya02

Description

@danya02

For instance, this example from Wikipedia is a perfectly cromulent QR code, as evidenced by other QR decoders such as this one.

Here's a copy of it in GIF format: ver10

However, if you try to decode it with this library, you get an error:

use rqrr;
use image;

fn main() {
    let img = match image::open("ver10.gif") {Ok(img)=>img, Err(err)=>panic!("unknown error while decoding img: {:?}", err)};
    let luma = img.to_luma();
    let mut prep_img = rqrr::PreparedImage::prepare(luma);
    let grids = prep_img.detect_grids();
    let res = grids[0].decode();
    let error = res.expect_err("This should succeed, but fails");
    match error {
        rqrr::DeQRError::InvalidVersion => (),
        _ => panic!("unexpected error in decoding?!"),
    }
}

(Sidenote: you might want to #[derive(PartialEq)] on rqrr::DeQRError -- the match construction is rather unwieldy compared to a simple assert_eq!, and the matches! macro is not yet stable.)

As far as I can tell, this happens because this error gets returned when the width of a QR code is greater than 40, not its version. The extreme case, version 40, has 177 modules per side, which is more than 40, but it doesn't mean that the grid itself is invalid. I've cloned the repo and changed this condition, and the rest of the code worked correctly in the version 10 case, so I'm pretty sure this is the one place that needs to be changed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions