In some cases, the decoder would find a section that looks like a QR Code, but it's smaller than 21x21, causing the version number calculation in readVersion() to go below zero and making the function return undefined. Because down the line there is a check for null, but not undefined, this causes the decoder to crash on buildFunctionPatternMask().
I found this to be more common on particularily grainy images like the ones from a notebook webcam.
The fix is a simple nullish coalescence to always return null and have the decoder correctly report that there is no valid QR Code in the region scanned. I also checked no other paths of this function could return anything other than a valid Version object or null.
Stacktrace:
qrcode.js:4459 Uncaught TypeError: Cannot read properties of undefined (reading 'versionNumber')
at buildFunctionPatternMask (qrcode.js:4459:38)
at readCodewords (qrcode.js:4485:31)
at decodeMatrix (qrcode.js:4668:21)
at decode (qrcode.js:4696:18)
at scan (qrcode.js:4887:21)
at Decoder.decode (qrcode.js:4945:20)
Note the library was transpiled in my case so line numbers are different.
In some cases, the decoder would find a section that looks like a QR Code, but it's smaller than 21x21, causing the version number calculation in
readVersion()
to go below zero and making the function return undefined. Because down the line there is a check fornull
, but notundefined
, this causes the decoder to crash onbuildFunctionPatternMask()
. I found this to be more common on particularily grainy images like the ones from a notebook webcam.The fix is a simple nullish coalescence to always return null and have the decoder correctly report that there is no valid QR Code in the region scanned. I also checked no other paths of this function could return anything other than a valid Version object or null.
Stacktrace:
Note the library was transpiled in my case so line numbers are different.