codebude / QRCoder

A pure C# Open Source QR Code implementation
MIT License
4.46k stars 1.09k forks source link

41 character bug #236

Closed PixMod closed 3 years ago

PixMod commented 4 years ago

Type of issue

[ x ] Bug
[ ] Question (e.g. about handling/usage)
[ ] Request for new feature/improvement

Expected Behavior

The QR code generated by 41 characters shall can be recognized.

Current Behavior

The QR code generated by 41 characters cannot be recognized.

Possible Solution (optional)

Steps to Reproduce (for bugs)

  1. QRCoder.QRCodeData code_data = code_generator.CreateQrCode("some string", QRCoder.QRCodeGenerator.ECCLevel.H, true, true, QRCoder.QRCodeGenerator.EciMode.Utf8);

    Note the length of "some string" should be 41, the content can be any ASCII characters, and the 4th parameter is set as true.

  2. Use the code_data to generate a bitmap.

    QRCoder.QRCode code = new QRCoder.QRCode(code_data);
    Bitmap bmp = code.GetGraphic(3, Color.Black, Color.White, true);
  3. Show the bmp on screen, use other application to scan the code.

  4. The QR code of bmp cannot be recognized.

Your Environment

Windows with .NetFramework v4.6

elisy commented 3 years ago

I can reproduce in 32 string length. .Net core 3.1, QRCoder 1.3.9

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("https://www.gallery.kz/p/20309pi", QRCodeGenerator.ECCLevel.Q, true, false, QRCodeGenerator.EciMode.Utf8);
QRCode qrCode = new QRCode(qrCodeData);
using (Bitmap image = qrCode.GetGraphic(pixelsPerModule, Color.Black, Color.White, true))

qrcore-error

If you change string with the same length the qrcode will be nonrecognizable too.

codebude commented 3 years ago

Hi @morrowind ,

I could re-produce the error. It happened if someone used ECI-mode and entered a payload which maxed out a specific QR code version. Unfortunately the additional headers for ECI mode weren't taken into size calculation.

The error was fixed in: https://github.com/codebude/QRCoder/commit/012dee3edb5be2508f35ebc6a3d1d9311dc2c256 And thus will be publicly available with the next Nuget package update.