Skip to content

Commit 38d1abe

Browse files
author
E Spelt
committed
fix: when using TBarcodeFormat.Auto certain QRCodes causes integer overflow in EAN parser. #133
1 parent 942df9c commit 38d1abe

4 files changed

Lines changed: 27 additions & 5 deletions

File tree

Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANReader.pas

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,12 @@ function TUPCEANReader.decodeRow(const rowNumber: Integer; const row: IBitArray;
451451
if startRange = nil then
452452
exit(nil);
453453

454-
Result := DoDecodeRow(rowNumber, row, startRange, hints);
454+
try
455+
Result := DoDecodeRow(rowNumber, row, startRange, hints);
456+
except
457+
result := nil;
458+
end;
459+
455460
end;
456461

457462
function TUPCEANReader.DoDecodeRow(const rowNumber: Integer;

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ The standard camera component is, I think too slow for Android and IOS. You need
3838

3939

4040
### Changes
41+
- v3.9.4
42+
- fix: when using TBarcodeFormat.Auto certain QRCodes causes integer overflow in EAN parser. https://github.com/Spelt/ZXing.Delphi/issues/133
4143
- v3.9.3
4244
- Demo app is Alexandria/Android compatible (Thanks igorbastosib and Patrick Prémartin)
4345
- fix: Some boundary check added (Thanks igorbastosib)

UnitTest/Test.pas

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,16 @@ procedure TZXingDelphiTest.AllQRCode();
533533
FreeAndNil(result);
534534
end;
535535

536+
537+
try
538+
result := Decode('QR-bug-overflow.png', TBarcodeFormat.QR_CODE);
539+
Assert.IsNotNull(result, ' Nil result');
540+
Assert.Contains(result.Text, '1653015096', false);
541+
542+
finally
543+
FreeAndNil(result);
544+
end;
545+
536546
end;
537547

538548
// This ones will only work when PURE_BARCODE is existing in the additional hints.
@@ -542,8 +552,6 @@ procedure TZXingDelphiTest.All_PURE_QRCode();
542552
hints: TDictionary<TDecodeHintType, TObject>;
543553
begin
544554

545-
546-
547555
hints := TDictionary<TDecodeHintType, TObject>.Create();
548556
hints.Add(TDecodeHintType.PURE_BARCODE, nil);
549557

@@ -1089,11 +1097,18 @@ procedure TZXingDelphiTest.AutoTypes;
10891097
var
10901098
result: TReadResult;
10911099
begin
1100+
1101+
try
1102+
result := Decode('QR-bug-overflow.png', TBarcodeFormat.EAN_13);
1103+
Assert.IsNull(result, ' Nil result');
1104+
finally
1105+
FreeAndNil(result);
1106+
end;
1107+
10921108
try
10931109
result := Decode('Code128.png', TBarcodeFormat.Auto);
10941110
Assert.IsNotNull(result, ' Nil result ');
10951111
Assert.IsTrue(result.Text.Equals('1234567'), 'Code 128 result Text Incorrect: ' + result.Text);
1096-
10971112
finally
10981113
FreeAndNil(result);
10991114
end;
@@ -1111,7 +1126,6 @@ procedure TZXingDelphiTest.AutoTypes;
11111126
result := Decode('Code128.png', TBarcodeFormat.Auto);
11121127
Assert.IsNotNull(result, ' Nil result ');
11131128
Assert.IsTrue(result.Text.Equals('1234567'), 'Code 128 result Text Incorrect: ' + result.Text);
1114-
11151129
finally
11161130
FreeAndNil(result);
11171131
end;
@@ -1214,6 +1228,7 @@ procedure TZXingDelphiTest.AutoTypes;
12141228
finally
12151229
FreeAndNil(result);
12161230
end;
1231+
12171232
end;
12181233

12191234
/// /////////////////////////////////////////////////////////////////////////////
440 KB
Loading

0 commit comments

Comments
 (0)