qrcode-kotlin
qrcode-kotlin copied to clipboard
Error correction level not taken into account with large piece of data
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
Passed that threshold, setting the error correction level has no effect:
myapp://aa/bbbbb?code1=wXtvQ0CZz49wonPSL94ZzsBOHDmlvOIx9iNB1GnobhIZ6qqu4Xbdj11jX3MztHslmNhoPSHoTCNNNJJWdftBoHtfhuczuu2uycQZKLkWy9tlaj0MpUa80hHxUi1aFJ5OuD9To0cuAdzyIg4HIiTeuJrWi38dsg71jOyslAgembgJ0Pc70SxRHKTDovKNy7sTylvXAFKUzKexXIjU7Bs64qFC2wMG1mLMobAPqcaZHiqjhTvHP82RuaV9rz8p0ubLQzM7GtEf2AyCALBc66xVchUYPQAFkYphuSw8l3ZTeB04vePHU84hwfsQfCxutcHXizixUIvnm7NN2NjniqeqYpMnIC4utspDxbjGRH2LlAVgHjY4xZ1iwAJrkw6wjHcHw7VC9kscyn8LF8p4LOHVbv7VzO1A9JNGtzFgvFJJfzPqgGTRdsrskGZa5QQUFiKrM2PqJSSLDchMF18nBVt33MEtWUpubpSqYfucnE5gCju4RMdg03fvV6MQMWfkB23pvjYvmlrN8yTfo1i2iOdMdkWLnhoOxiXC0G2fOX5QmuX0kFDTQ9hDPw3CTVCYeia0ui3N9LNkiZlB6aqrVdVgJe3vpuOJVmE2hWt7EZSlwGHUUQLypD0xry2LGdZXogJsxH6CSfDJDVwNz9VdTlfVwNp1IQNTzGENjjIxgfnYRq3sNgWz5Ht9FlyFuzXBaZMltYBDbmadwnQlwb46UeCptWybw1CizfMrFHxkpM9XfohXzqfLDQgasrwlqsK7YhCztu9SYtb6iEv0dONZewEZVz67Ay5xnb580yTiTOqW7yr5k7NBfGLpd7ki0aJhI22Ofbab
To Reproduce Steps to reproduce the behavior. For example:
- Create a QRCode instance with a 859 characters like the second one posted above
- Invoke
render()with a low error correction level - See result
Expected behavior
Error correction level would be respected no matter the size of the data
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)
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
Thanks a lot for your quick response @g0dkar! Did you get a chance to look into it? 🙏
Same crash here. How to lower the level without crash?