Merge lp:~chciken/qr-tools/fix-index-error into lp:qr-tools

Proposed by Niko Zurstraßen
Status: Merged
Approved by: Ramiro Algozino
Approved revision: 44
Merged at revision: 44
Proposed branch: lp:~chciken/qr-tools/fix-index-error
Merge into: lp:qr-tools
Diff against target: 37 lines (+18/-7)
1 file modified
qtqr.py (+18/-7)
To merge this branch: bzr merge lp:~chciken/qr-tools/fix-index-error
Reviewer Review Type Date Requested Status
Ramiro Algozino Approve
Review via email: mp+395971@code.launchpad.net

Commit message

Wrapping a try/except block around data_decode.
This fixes segmentation faults which might occur when decoding broken qr codes with a webcam.

Description of the change

This fixes bug #1909309.

To post a comment you must log in.
Revision history for this message
Ramiro Algozino (algozino) wrote :

lgtm. Thank you for taking care of this.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'qtqr.py'
2--- qtqr.py 2020-10-24 11:53:42 +0000
3+++ qtqr.py 2021-01-08 07:15:30 +0000
4@@ -897,15 +897,26 @@
5 if device:
6 qr = QR()
7 qr.decode_webcam(device=device)
8- if qr.data_decode[qr.data_type](qr.data) == 'NULL':
9- QtWidgets.QMessageBox.warning(
10- self,
11- self.tr("Decoding Failed"),
12- self.tr("<p>Oops! no code was found.<br /> Maybe your webcam didn't focus.</p>"),
13- QtWidgets.QMessageBox.Ok
14+ try:
15+ matchData = qr.data_decode[qr.data_type](qr.data)
16+ except IndexError:
17+ QtWidgets.QMessageBox.warning(
18+ self,
19+ self.tr("Decoding Failed"),
20+ self.tr(f"<p>oops! Your code seems to be of type '{qr.data_type}', but no decoding for data '{qr.data}' could be found.</p>"),
21+ QtWidgets.QMessageBox.Ok
22 )
23 else:
24- self.showInfo(qr)
25+ if matchData == 'NULL':
26+ QtWidgets.QMessageBox.warning(
27+ self,
28+ self.tr("Decoding Failed"),
29+ self.tr("<p>Oops! no code was found.<br /> Maybe your webcam didn't focus.</p>"),
30+ QtWidgets.QMessageBox.Ok
31+ )
32+ else:
33+ self.showInfo(qr)
34+
35 qr.destroy()
36
37 def about(self):

Subscribers

People subscribed via source and target branches