Skip to content

Commit 96dab6b

Browse files
authored
Merge pull request opencv#26532 from mshabunin:fix-qr-bitstream
objdetect: fix invalid vector access in QR de/encoder
2 parents bef3585 + e953fcf commit 96dab6b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

modules/objdetect/src/qrcode_encoder.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -711,17 +711,17 @@ void QRCodeEncoderImpl::padBitStream()
711711
else if (pad_num <= 4)
712712
{
713713
int payload_size = (int)payload.size();
714-
writeDecNumber(0, payload_size, payload);
714+
payload.insert(payload.end(), payload_size, 0);
715715
}
716716
else
717717
{
718-
writeDecNumber(0, 4, payload);
718+
payload.insert(payload.end(), 4, 0);
719719

720720
int i = payload.size() % bits;
721721

722722
if (i != 0)
723723
{
724-
writeDecNumber(0, bits - i, payload);
724+
payload.insert(payload.end(), bits - i, 0);
725725
}
726726
pad_num = total_data - (int)payload.size();
727727

@@ -1329,11 +1329,12 @@ class QRCodeDecoderImpl : public QRCodeDecoder {
13291329

13301330
int val = 0;
13311331
while (bits >= actualBits) {
1332+
CV_CheckLT(idx, data.size(), "Not enough bits in the bitstream");
13321333
val |= data[idx++] << (bits - actualBits);
13331334
bits -= actualBits;
13341335
actualBits = 8;
13351336
}
1336-
if (bits) {
1337+
if (bits && idx < data.size()) {
13371338
val |= data[idx] >> (actualBits - bits);
13381339
actualBits -= bits;
13391340
data[idx] &= 255 >> (8 - actualBits);

0 commit comments

Comments
 (0)