From 1b36a381e80ce20f8bdd3dfc849434c7ed1a4496 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 12 Apr 2017 13:20:22 +0200 Subject: [PATCH] Fix buffer length for QR code gen. (#5447) --- js/src/ui/QrCode/qrSize.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/src/ui/QrCode/qrSize.js b/js/src/ui/QrCode/qrSize.js index 2671bb532..8440458ac 100644 --- a/js/src/ui/QrCode/qrSize.js +++ b/js/src/ui/QrCode/qrSize.js @@ -69,7 +69,9 @@ const QR_SIZES = [ export function calculateType (lengthBytes, errorLevel = 'M') { let type = 5; - while (type < 40 && lengthBytes > QR_SIZES[errorLevel][type - 1]) { + // subtract 3 from the capacities, since we need 2 bits for the mode and a + // bunch more for the length. + while (type < 40 && lengthBytes > QR_SIZES[errorLevel][type - 1] - 3) { type++; }