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

Malformed padding when number of bits is a multiple of 8 #123

Open
simon-staal opened this issue May 31, 2023 · 3 comments
Open

Malformed padding when number of bits is a multiple of 8 #123

simon-staal opened this issue May 31, 2023 · 3 comments

Comments

@simon-staal
Copy link

There is a likely bug in the implementation when encoding 4-digit numbers into a 1-H QR code. This causes QR codes generated by segno to fail being captured when using BoofCV - see here

@lessthanoptimal
Copy link

Thought I would explain in some more detail since I'm the person claiming it's not a bug in the decoder but a bug in the encoder:

The padding that's added after the message is supposed to be added after the last byte. When the number of bits is divisible by 8 it starts it one byte after it should. The reason most encoders don't have an issue is that they ignore the padding bytes.

I suspect the code calculates the first byte that it should add padding using this formula:

paddingByte = bits/8 + 1

If you have a 12 bit message this will return byte 2, which is correct, but if you have a 16 bit message it will return 3, which is incorrect.

Illustration, '*' is a message bit, '-' is an unused bit

[********][****----][padding][padding]  <--- correct
[********][********][--------][padding] <-- wrong. skips first byte

Here's one possible correct formula

paddingBytes = bits/8 + (bits%8 == 0 ? 0 : 1)

@heuer
Copy link
Owner

heuer commented Jun 1, 2023

Thanks for the information. I'll look into that end of next week

@simon-staal
Copy link
Author

simon-staal commented Jun 15, 2023

Just a quick update on this, the padding issue likely affects micro QR codes as well based on some of the testing I've done with those - obtaining the same errors with from 1-H codes above on M4-Q QR codes.

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

3 participants