LittleSecrets / zend-framework-matrixcode-module

Automatically exported from code.google.com/p/zend-framework-matrixcode-module
0 stars 0 forks source link

Error in the generator makes invalid codes from short alphanumiric strings #9

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The svn code and also http://qrcode.littleidiot.be/ produce an unreadable code 
for the string:
TEL:123456789
As tested with Barcode Scanner on Android.

This might be related to issue #1 but I didn't see a clear test case there to 
be sure.

I have narrowed down the error and written a patch.

There seems to be an error in the generator (Qrcode.php) in the section 
commented "Divide data in 8 bit chuncks" which was refactored (compared to the 
swetake code).

It uses the value of $data_counter but $data_counter is not incremented when a 
0000 terminator is added in the previous step.

Since it seemed safer than trying to make sure all the legacy code leaves 
$data_counter in the state we expect I instead counted the $data_value array.

Here is the patch:

Index: Matrixcode/Qrcode.php
===================================================================
--- Matrixcode/Qrcode.php   (revision 11)
+++ Matrixcode/Qrcode.php   (working copy)
@@ -532,7 +532,8 @@
        //
        $codewords = array();
        $full_bit_string = '';
-       for($i=0; $i<$data_counter; $i++) {
+       $num_data_blocks=count($data_value);
+       for($i=0; $i<$num_data_blocks; $i++) {
            $full_bit_string .= str_pad(decbin($data_value[$i]), $data_bits[$i], '0', STR_PAD_LEFT);
        }
        // padd the data with 0 until the length is a multiple of 8

Original issue reported on code.google.com by c...@caff.cx on 8 Feb 2012 at 11:26

GoogleCodeExporter commented 9 years ago
I had the same problem. When I scanned the generated QRcode my mobile phones 
returned the original code followed by many additional, some kind of random 
generated, characters. Applying this patch solved it. It would be nice if this 
fix was included in the source.

Thanks for debugging and fixing!

Roland Leurs

Original comment by rgmle...@gmail.com on 24 May 2013 at 5:59