diff --git a/Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANReader.pas b/Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANReader.pas index 7ce093a..1d289b3 100644 --- a/Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANReader.pas +++ b/Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANReader.pas @@ -451,7 +451,12 @@ function TUPCEANReader.decodeRow(const rowNumber: Integer; const row: IBitArray; if startRange = nil then exit(nil); - Result := DoDecodeRow(rowNumber, row, startRange, hints); + try + Result := DoDecodeRow(rowNumber, row, startRange, hints); + except + result := nil; + end; + end; function TUPCEANReader.DoDecodeRow(const rowNumber: Integer; diff --git a/README.md b/README.md index cd49c17..3109733 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ The standard camera component is, I think too slow for Android and IOS. You need ### Changes +- v3.9.4 + - fix: when using TBarcodeFormat.Auto certain QRCodes causes integer overflow in EAN parser. https://github.com/Spelt/ZXing.Delphi/issues/133 - v3.9.3 - Demo app is Alexandria/Android compatible (Thanks igorbastosib and Patrick Prémartin) - fix: Some boundary check added (Thanks igorbastosib) diff --git a/UnitTest/Test.pas b/UnitTest/Test.pas index 2b07497..c3ee408 100644 --- a/UnitTest/Test.pas +++ b/UnitTest/Test.pas @@ -533,6 +533,16 @@ procedure TZXingDelphiTest.AllQRCode(); FreeAndNil(result); end; + + try + result := Decode('QR-bug-overflow.png', TBarcodeFormat.QR_CODE); + Assert.IsNotNull(result, ' Nil result'); + Assert.Contains(result.Text, '1653015096', false); + + finally + FreeAndNil(result); + end; + end; // This ones will only work when PURE_BARCODE is existing in the additional hints. @@ -542,8 +552,6 @@ procedure TZXingDelphiTest.All_PURE_QRCode(); hints: TDictionary; begin - - hints := TDictionary.Create(); hints.Add(TDecodeHintType.PURE_BARCODE, nil); @@ -1089,11 +1097,18 @@ procedure TZXingDelphiTest.AutoTypes; var result: TReadResult; begin + + try + result := Decode('QR-bug-overflow.png', TBarcodeFormat.EAN_13); + Assert.IsNull(result, ' Nil result'); + finally + FreeAndNil(result); + end; + try result := Decode('Code128.png', TBarcodeFormat.Auto); Assert.IsNotNull(result, ' Nil result '); Assert.IsTrue(result.Text.Equals('1234567'), 'Code 128 result Text Incorrect: ' + result.Text); - finally FreeAndNil(result); end; @@ -1111,7 +1126,6 @@ procedure TZXingDelphiTest.AutoTypes; result := Decode('Code128.png', TBarcodeFormat.Auto); Assert.IsNotNull(result, ' Nil result '); Assert.IsTrue(result.Text.Equals('1234567'), 'Code 128 result Text Incorrect: ' + result.Text); - finally FreeAndNil(result); end; @@ -1214,6 +1228,7 @@ procedure TZXingDelphiTest.AutoTypes; finally FreeAndNil(result); end; + end; /// ///////////////////////////////////////////////////////////////////////////// diff --git a/unitTest/Images/QR-bug-overflow.png b/unitTest/Images/QR-bug-overflow.png new file mode 100644 index 0000000..a62f7bc Binary files /dev/null and b/unitTest/Images/QR-bug-overflow.png differ