fukuchi / libqrencode

A fast and compact QR Code encoding library
https://fukuchi.org/works/qrencode/
GNU Lesser General Public License v2.1
2.57k stars 599 forks source link

The library doesn't respect the encoding standard #204

Closed Bolayniuss closed 1 year ago

Bolayniuss commented 1 year ago

Hi, I've been using this library (and an older version of it) since quite some time now and it was working perfectly so far. But recently I've found an issue while encoding v3 QR (it probably also happens on other versions). In some cases the library is not able to encode strings in 8bit mode that should fit in the QR according the the standard.

For example the lib can't produce a QR version 3 with ECC=Q for that string aaaaaaaaaaaaaaaa1111WWWWaaaaaaaa which is 32 char long, while the standard says that it's possible (https://www.qrcode.com/en/about/version.html).

I believe that the issue comes from the way the library is encoding string by switching between encoding mode to maximize the capacity of the QR. An easy fix would be to add a flag to disable this smart mechanism or activate the mechanism only if it's needed (if the string could not fit in the provided qr version and encoding mode.

I also think that this could be the root cause of issue https://github.com/fukuchi/libqrencode/issues/115 as from my experience some reading library did not implement the mixed encoding mode and only support full alpha-numerical, kanji and 8bit modes.

Bolayniuss commented 1 year ago

My bad, I missed the fact that we can force 8bit encoding... That said, it's a bit strange that the smart encoding way is not catching this special case and doesn't fallback to a full 8bit encoding mode.