qrcode-kotlin icon indicating copy to clipboard operation
qrcode-kotlin copied to clipboard

Error correction level not taken into account with large piece of data

Open romainpiel opened this issue 1 year ago • 4 comments
trafficstars

Describe the bug version: 3.3.0

I'm playing with this library to render very QR codes for very long urls (900 characters) and setting the ErrorCorrectionLevel doesn't change anything. Digging a bit more, the error correction level is respected until 858 bytes of data, for example:

myapp://aa/bbbbb?code1=wXtvQ0CZz49wonPSL94ZzsBOHDmlvOIx9iNB1GnobhIZ6qqu4Xbdj11jX3MztHslmNhoPSHoTCNNNJJWdftBoHtfhuczuu2uycQZKLkWy9tlaj0MpUa80hHxUi1aFJ5OuD9To0cuAdzyIg4HIiTeuJrWi38dsg71jOyslAgembgJ0Pc70SxRHKTDovKNy7sTylvXAFKUzKexXIjU7Bs64qFC2wMG1mLMobAPqcaZHiqjhTvHP82RuaV9rz8p0ubLQzM7GtEf2AyCALBc66xVchUYPQAFkYphuSw8l3ZTeB04vePHU84hwfsQfCxutcHXizixUIvnm7NN2NjniqeqYpMnIC4utspDxbjGRH2LlAVgHjY4xZ1iwAJrkw6wjHcHw7VC9kscyn8LF8p4LOHVbv7VzO1A9JNGtzFgvFJJfzPqgGTRdsrskGZa5QQUFiKrM2PqJSSLDchMF18nBVt33MEtWUpubpSqYfucnE5gCju4RMdg03fvV6MQMWfkB23pvjYvmlrN8yTfo1i2iOdMdkWLnhoOxiXC0G2fOX5QmuX0kFDTQ9hDPw3CTVCYeia0ui3N9LNkiZlB6aqrVdVgJe3vpuOJVmE2hWt7EZSlwGHUUQLypD0xry2LGdZXogJsxH6CSfDJDVwNz9VdTlfVwNp1IQNTzGENjjIxgfnYRq3sNgWz5Ht9FlyFuzXBaZMltYBDbmadwnQlwb46UeCptWybw1CizfMrFHxkpM9XfohXzqfLDQgasrwlqsK7YhCztu9SYtb6iEv0dONZewEZVz67Ay5xnb580yTiTOqW7yr5k7NBfGLpd7ki0aJhI22Ofba

image

Passed that threshold, setting the error correction level has no effect:

myapp://aa/bbbbb?code1=wXtvQ0CZz49wonPSL94ZzsBOHDmlvOIx9iNB1GnobhIZ6qqu4Xbdj11jX3MztHslmNhoPSHoTCNNNJJWdftBoHtfhuczuu2uycQZKLkWy9tlaj0MpUa80hHxUi1aFJ5OuD9To0cuAdzyIg4HIiTeuJrWi38dsg71jOyslAgembgJ0Pc70SxRHKTDovKNy7sTylvXAFKUzKexXIjU7Bs64qFC2wMG1mLMobAPqcaZHiqjhTvHP82RuaV9rz8p0ubLQzM7GtEf2AyCALBc66xVchUYPQAFkYphuSw8l3ZTeB04vePHU84hwfsQfCxutcHXizixUIvnm7NN2NjniqeqYpMnIC4utspDxbjGRH2LlAVgHjY4xZ1iwAJrkw6wjHcHw7VC9kscyn8LF8p4LOHVbv7VzO1A9JNGtzFgvFJJfzPqgGTRdsrskGZa5QQUFiKrM2PqJSSLDchMF18nBVt33MEtWUpubpSqYfucnE5gCju4RMdg03fvV6MQMWfkB23pvjYvmlrN8yTfo1i2iOdMdkWLnhoOxiXC0G2fOX5QmuX0kFDTQ9hDPw3CTVCYeia0ui3N9LNkiZlB6aqrVdVgJe3vpuOJVmE2hWt7EZSlwGHUUQLypD0xry2LGdZXogJsxH6CSfDJDVwNz9VdTlfVwNp1IQNTzGENjjIxgfnYRq3sNgWz5Ht9FlyFuzXBaZMltYBDbmadwnQlwb46UeCptWybw1CizfMrFHxkpM9XfohXzqfLDQgasrwlqsK7YhCztu9SYtb6iEv0dONZewEZVz67Ay5xnb580yTiTOqW7yr5k7NBfGLpd7ki0aJhI22Ofbab

image

To Reproduce Steps to reproduce the behavior. For example:

  1. Create a QRCode instance with a 859 characters like the second one posted above
  2. Invoke render() with a low error correction level
  3. See result

Expected behavior

Error correction level would be respected no matter the size of the data

romainpiel avatar May 02 '24 12:05 romainpiel

I've tested this again by upgrading to 4.2.0 and rendering a 858 bytes string with a low error correction level results in a crash:

            java.lang.IllegalArgumentException: Code length overflow (3604 > 1576)
             at qrcode.raw.QRCodeProcessor.createData(QRCodeProcessor.kt:359)
             at qrcode.raw.QRCodeProcessor.encode(QRCodeProcessor.kt:337)
             at qrcode.raw.QRCodeProcessor.encode$default(QRCodeProcessor.kt:317)
             at qrcode.QRCode.<init>(QRCode.kt:114)
             at qrcode.QRCodeBuilder.build(QRCodeBuilder.kt:286)

romainpiel avatar May 02 '24 14:05 romainpiel

Heya @romainpiel! I'll dig a bit around!

I've done some testing with the data you provided and indeed the ECL should not interfere with the result 🤔

Right now, I'm thinking it is related to something called TypeNumber, which is calculated from the ECL and the data type itself. I'll both fix this and perhaps expose these numbers so users can set them themselves ^^

I'll work on this issue over the weekend 😬

Thanks for bringing it in <3

g0dkar avatar May 09 '24 19:05 g0dkar

Thanks a lot for your quick response @g0dkar! Did you get a chance to look into it? 🙏

romainpiel avatar Jun 03 '24 12:06 romainpiel

Same crash here. How to lower the level without crash?

b95505017 avatar Dec 25 '24 03:12 b95505017