zxing-js / library

Multi-format 1D/2D barcode image processing library, usable in JavaScript ecosystem.
https://zxing-js.github.io/library/
Apache License 2.0
2.5k stars 546 forks source link

Library randomly fires hallucinated "successful" scans #612

Open mattmattmatt opened 3 months ago

mattmattmatt commented 3 months ago

Describe the bug When a Scanner mini-app is left open for a while, the underlying barcode detection library starts firing seemingly random "hallucinated" scans.

These scans are of BarcodeFormat value 12, aka RSS 14 bar codes. The decoding of those is handled in UPCEANReader.js as provided by the ZXing library.

Once a hallucinated code is fired (e.g. 201215783246180), it is that code (and not other random codes) that continue to fire. Different instances of the bug will fire different codes.

I have been unable to reproduce exactly when or why that happens, but once it does, only resetting the scanner/the underlying library stops the hallucinated scans. Even presenting a valid barcode/qr code to the camera will not be recognized, as the library is "busy" recognizing the hallucinated code.

To Reproduce I wish I had a way to reproduce this reliably. Sometimes it happens ~30 secs into a scanner being left running, sometimes several minutes. Sometimes it does not happen at all.

Expected behavior When no barcode is presented to the camera, result handlers do not fire.

Desktop (please complete the following information):

Additional context I tried to see if others ran into this issue but did not find any reports.

This is how the library is instantiated in our React app:

  const codeReader = new BrowserMultiFormatReader(undefined, timeBetweenScansMs)
  codeReader.decodeFromVideoDevice(cameraId, videoRef.current, handleResult)

The described behavior is also present when passing a video element's id to the Reader, not a DOM element.