Skip to content

Commit

Permalink
fix: when using TBarcodeFormat.Auto certain QRCodes causes integer ov…
Browse files Browse the repository at this point in the history
…erflow in EAN parser. #133
  • Loading branch information
E Spelt committed Jun 3, 2022
1 parent 942df9c commit 38d1abe
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
7 changes: 6 additions & 1 deletion Lib/Classes/1D Barcodes/ZXing.OneD.UPCEANReader.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 19 additions & 4 deletions UnitTest/Test.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -542,8 +552,6 @@ procedure TZXingDelphiTest.All_PURE_QRCode();
hints: TDictionary<TDecodeHintType, TObject>;
begin



hints := TDictionary<TDecodeHintType, TObject>.Create();
hints.Add(TDecodeHintType.PURE_BARCODE, nil);

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -1214,6 +1228,7 @@ procedure TZXingDelphiTest.AutoTypes;
finally
FreeAndNil(result);
end;

end;

/// /////////////////////////////////////////////////////////////////////////////
Expand Down
Binary file added unitTest/Images/QR-bug-overflow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 38d1abe

Please sign in to comment.