Public bug reported:

The bug is exposed by the program qtqr, but the root cause is an
apparent mismatch between python-qrtools and python-pil that can be
fixed with a one-line patch to qrtools.py in python-qrtools.

Below I've given the output of enough commands to fully reproduce my
setup. You can use xxd -r to create the same PNG that I used, or you can
make your own with qtqr (it won't matter).


$ uname -prs
Linux 4.4.0-21-generic x86_64


$ lsb_release -rd
Description:    Ubuntu 16.04 LTS
Release:        16.04


# This is a test QR code that I created with qtqr; as seen below, the content 
is just "test".
$ xxd test.png 
00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452  .PNG........IHDR
00000010: 0000 0057 0000 0057 0103 0000 004b 064b  ...W...W.....K.K
00000020: 2f00 0000 0650 4c54 4500 0000 ffff ffa5  /....PLTE.......
00000030: d99f dd00 0000 0274 524e 53ff ffc8 b5df  .......tRNS.....
00000040: c700 0000 0970 4859 7300 000b 1200 000b  .....pHYs.......
00000050: 1201 d2dd 7efc 0000 00ba 4944 4154 388d  ....~.....IDAT8.
00000060: cdd3 3b0e c320 0c00 5057 1db2 e504 96b8  ..;.. ..PW......
00000070: 86b7 5c89 5c20 a827 e895 d87c 8d48 bd00  ..\.\ .'...|.H..
00000080: 6c0c 48ae 53a5 c942 ccd8 7a7a 832d 7f10  l.H.S..B..zz.-..
00000090: 2067 c05f 3801 2c84 00ce 7096 ba40 0d62   g._8.,...p..@.b
000000a0: 3aa2 27f4 43c7 0bd5 ae03 63c7 a24d f198  :.'.C.....c..M..
000000b0: a169 9d7f e673 97a6 3512 b9e3 264d a701  .i...s..5...&M..
000000c0: 00d6 c096 85ef 4fae e367 b62b e758 03bb  ......O..g.+.X..
000000d0: 3489 e5b2 adb0 e75f 3811 8e03 0289 618d  4......_8.....a.
000000e0: 5c5e 393a c37a 074f eb5e 7b61 6d3a c77b  \^9:.z.O.^{am:.{
000000f0: fede b66d 7d5f 583d 751c b4a4 88ed 99dd  ...m}_X=u.......
00000100: 839d 654d e61a 8a18 dee6 9ff0 569c e15f  ..eM........V.._
00000110: fdb5 b6df 4296 b3b4 dc52 71ee 0000 0000  ....B....Rq.....
00000120: 4945 4e44 ae42 6082                      IEND.B`.


$ apt-cache policy zbar-tools 
zbar-tools:
  Installed: 0.10+doc-10ubuntu1
  Candidate: 0.10+doc-10ubuntu1
  Version table:
 *** 0.10+doc-10ubuntu1 500
        500 http://us.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
        100 /var/lib/dpkg/status

$ zbarimg test.png 
QR-Code:test
scanned 1 barcode symbols from 1 images in 0.01 seconds


$ apt-cache policy qtqr
qtqr:
  Installed: 1.4~bzr21-1
  Candidate: 1.4~bzr21-1
  Version table:
 *** 1.4~bzr21-1 500
        500 http://us.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
        500 http://us.archive.ubuntu.com/ubuntu xenial/universe i386 Packages
        100 /var/lib/dpkg/status

$ qtqr


### Manually select "Decode" and then "Decode from File" and choose test.png 
(or any PNG containing a QR code); the operation fails, and the following is 
printed on the console by qtqr:


/usr/lib/python2.7/dist-packages/PIL/Image.py:870: UserWarning: Palette images 
with Transparency   expressed in bytes should be converted to RGBA images
  'to RGBA images')
Traceback (most recent call last):
  File "/usr/bin/qtqr", line 540, in decodeFile
    if qr.decode():
  File "/usr/lib/python2.7/dist-packages/qrtools.py", line 181, in decode
    raw = pil.tostring()
  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 695, in tostring
    "Please call tobytes() instead.")
Exception: tostring() has been removed. Please call tobytes() instead.


$ dpkg --search /usr/lib/python2.7/dist-packages/qrtools.py
python-qrtools: /usr/lib/python2.7/dist-packages/qrtools.py

$ apt-cache policy python-qrtools 
python-qrtools:
  Installed: 1.4~bzr21-1
  Candidate: 1.4~bzr21-1
  Version table:
 *** 1.4~bzr21-1 500
        500 http://us.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
        500 http://us.archive.ubuntu.com/ubuntu xenial/universe i386 Packages
        100 /var/lib/dpkg/status


$ dpkg --search  /usr/lib/python2.7/dist-packages/PIL/Image.py
python-pil:amd64: /usr/lib/python2.7/dist-packages/PIL/Image.py

$ apt-cache policy python-pil
python-pil:
  Installed: 3.1.2-0ubuntu1
  Candidate: 3.1.2-0ubuntu1
  Version table:
 *** 3.1.2-0ubuntu1 500
        500 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 Packages
        100 /var/lib/dpkg/status


Based on the code at Image.py:695, the call to tostring() is obviously an 
error; I've confirmed that the following patch fixes the problem.


$diff --git a/qrtools.py.orig b/qrtools.py.fixed
index 3e98469..68546e4 100644
--- a/qrtools.py.orig
+++ b/qrtools.py.fixed
@@ -178,7 +178,7 @@ class QR(object):
             # obtain image data
             pil = Image.open(self.filename).convert('L')
             width, height = pil.size
-            raw = pil.tostring()
+            raw = pil.tobytes()
             # wrap image data
             image = zbar.Image(width, height, 'Y800', raw)
             # scan the image for barcodes


When this patch is applied to /usr/lib/python2.7/dist-packages/qrtools.py, qtqr 
is able to correctly decode the test image.

** Affects: python-qrtools (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1574162

Title:
  qrtools.py calls tostring() instead of tobytes()

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/python-qrtools/+bug/1574162/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to