objdetect: fix invalid vector access in QR encoder

This commit is contained in:
Maksim Shabunin 2024-11-26 18:17:51 +03:00
parent bef3585245
commit e953fcfaa4

View File

@ -711,17 +711,17 @@ void QRCodeEncoderImpl::padBitStream()
else if (pad_num <= 4) else if (pad_num <= 4)
{ {
int payload_size = (int)payload.size(); int payload_size = (int)payload.size();
writeDecNumber(0, payload_size, payload); payload.insert(payload.end(), payload_size, 0);
} }
else else
{ {
writeDecNumber(0, 4, payload); payload.insert(payload.end(), 4, 0);
int i = payload.size() % bits; int i = payload.size() % bits;
if (i != 0) if (i != 0)
{ {
writeDecNumber(0, bits - i, payload); payload.insert(payload.end(), bits - i, 0);
} }
pad_num = total_data - (int)payload.size(); pad_num = total_data - (int)payload.size();
@ -1329,11 +1329,12 @@ private:
int val = 0; int val = 0;
while (bits >= actualBits) { while (bits >= actualBits) {
CV_CheckLT(idx, data.size(), "Not enough bits in the bitstream");
val |= data[idx++] << (bits - actualBits); val |= data[idx++] << (bits - actualBits);
bits -= actualBits; bits -= actualBits;
actualBits = 8; actualBits = 8;
} }
if (bits) { if (bits && idx < data.size()) {
val |= data[idx] >> (actualBits - bits); val |= data[idx] >> (actualBits - bits);
actualBits -= bits; actualBits -= bits;
data[idx] &= 255 >> (8 - actualBits); data[idx] &= 255 >> (8 - actualBits);