segmentation fault when decoding with webcam

Bug #1909309 reported by Niko Zurstraßen
16
This bug affects 2 people
Affects Status Importance Assigned to Milestone
QR Tools
Fix Released
Medium
Unassigned

Bug Description

Hi all,

When trying to decode wifi codes with my webcam, qtqr crashes with the following output:

Traceback (most recent call last):
  File "/usr/bin/qtqr", line 723, in decodeWebcam
    if qr.data_decode[qr.data_type](qr.data) == 'NULL':
  File "/usr/lib/python2.7/dist-packages/qrtools.py", line 92, in <lambda>
    'wifi' : lambda data: re.findall(u"WIFI:S:(.*);T:(.*);P:(.*);;", data, re.IGNORECASE)[0],
IndexError: list index

After a little investigation I found out that my smartphone generates the qr codes, which I try to scan, incorrectly. Instead of two semicolons the MeCard like format ends with only one semicolon.
Thus, the regex-expression yields no result and the indexing with [0] fails.

As a fix I would suggest to put "qr.data_decode[qr.data_type](qr.data)" into a try/except block
and show an error box including the undecodable string if there was an IndexError.

Any ideas/comments on that?

Related branches

Revision history for this message
Ramiro Algozino (algozino) wrote : Re: [Bug 1909309] [NEW] segmentation fault when decoding with webcam

Hi!

Thanks for the report. I agree that the regex is failing and then making the app crash. I think that the right way would be to wrap all the decoders in a try-catch and just fallback to show the decoded text. I wouldn’t touch the regex because the QR code is malformed.

Feel free to send a PR!

Ramiro Algozino
https://algozino.com.ar/
On 25 Dec 2020, 10:25 +0100, Niko Zurstraßen <email address hidden>, wrote:
> Public bug reported:
>
> Hi all,
>
> When trying to decode wifi codes with my webcam, qtqr crashes with the
> following output:
>
> Traceback (most recent call last):
> File "/usr/bin/qtqr", line 723, in decodeWebcam
> if qr.data_decode[qr.data_type](qr.data) == 'NULL':
> File "/usr/lib/python2.7/dist-packages/qrtools.py", line 92, in <lambda>
> 'wifi' : lambda data: re.findall(u"WIFI:S:(.*);T:(.*);P:(.*);;", data, re.IGNORECASE)[0],
> IndexError: list index
>
>
> After a little investigation I found out that my smartphone generates the qr codes, which I try to scan, incorrectly. Instead of two semicolons the MeCard like format ends with only one semicolon.
> Thus, the regex-expression yields no result and the indexing with [0] fails.
>
> As a fix I would suggest to put "qr.data_decode[qr.data_type](qr.data)" into a try/except block
> and show an error box including the undecodable string if there was an IndexError.
>
> Any ideas/comments on that?
>
> ** Affects: qr-tools
> Importance: Undecided
> Status: New
>
> --
> You received this bug notification because you are a member of QR Tools
> Team, which is subscribed to QR Tools.
> https://bugs.launchpad.net/bugs/1909309
>
> Title:
> segmentation fault when decoding with webcam
>
> Status in QR Tools:
> New
>
> Bug description:
> Hi all,
>
> When trying to decode wifi codes with my webcam, qtqr crashes with the
> following output:
>
> Traceback (most recent call last):
> File "/usr/bin/qtqr", line 723, in decodeWebcam
> if qr.data_decode[qr.data_type](qr.data) == 'NULL':
> File "/usr/lib/python2.7/dist-packages/qrtools.py", line 92, in <lambda>
> 'wifi' : lambda data: re.findall(u"WIFI:S:(.*);T:(.*);P:(.*);;", data, re.IGNORECASE)[0],
> IndexError: list index
>
>
> After a little investigation I found out that my smartphone generates the qr codes, which I try to scan, incorrectly. Instead of two semicolons the MeCard like format ends with only one semicolon.
> Thus, the regex-expression yields no result and the indexing with [0] fails.
>
> As a fix I would suggest to put "qr.data_decode[qr.data_type](qr.data)" into a try/except block
> and show an error box including the undecodable string if there was an IndexError.
>
> Any ideas/comments on that?
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/qr-tools/+bug/1909309/+subscriptions

Revision history for this message
Niko Zurstraßen (chciken) wrote :

I sent a PR.
Please tell me if can improve something.

Revision history for this message
Ramiro Algozino (algozino) wrote :

Hi Niko,

Thank you for taking care of this. I've merged your PR, the fix should be available soon on the Daily PPA (tonight - tomorrow at max).

Best regards and have a happy new year!

Changed in qr-tools:
status: New → Fix Committed
importance: Undecided → Medium
Revision history for this message
X-Ander (x-ander) wrote :

Hi! I have found out that some smartphones generate wifi QR-codes having different order of attributes. Something like:

   WIFI:T:WPA;P:<key>;S:<ssid>;

So the program crashes. I have replaced the regular expression in qrtools.py by:

   WIFI:(?:;|S:([^;]*);|T:([^;]*);|P:([^;]*);|H:([^;]*);)+

Now it works. Attributes may be in random order, and may be missing as well.

Revision history for this message
Ramiro Algozino (algozino) wrote :

Thanks X-Ander, that makes sense actually!

I've pushed the regex you provided, should be available in the daily PPA soon.

Cheers!

Changed in qr-tools:
status: Fix Committed → Fix Released
milestone: none → 2.2
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.