void DecodedBitStreamParser::append(std::string& result, const char* bufIn, size_t nIn,
ErrorHandler& err_handler) {
- if (err_handler.ErrCode()) return;
+ // avoid null pointer exception
+ if (err_handler.ErrCode() || bufIn == nullptr) return;
#ifndef NO_ICONV_INSIDE
if (nIn == 0) {
return;
CharacterSetECI* currentCharacterSetECI,
ArrayRef<ArrayRef<char> >& byteSegments,
ErrorHandler& err_handler) {
- int nBytes = count;
BitSource& bits(*bits_);
// Don't crash trying to read more bits than we have available.
int available = bits.available();
// try to repair count data if count data is invalid
if (count * 8 > available) {
- count = (available + 7 / 8);
+ count = (available + 7) / 8;
}
+ size_t nBytes = count;
+
+ ArrayRef<char> bytes_(nBytes);
+ // issue https://github.com/opencv/opencv_contrib/issues/3478
+ if (bytes_->empty())
+ return;
- ArrayRef<char> bytes_(count);
char* readBytes = &(*bytes_)[0];
for (int i = 0; i < count; i++) {
// readBytes[i] = (char) bits.readBits(8);
INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_Curved, testing::ValuesIn(qrcode_images_curved));
// INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_Multi, testing::ValuesIn(qrcode_images_multiple));
+TEST(Objdetect_QRCode_bug, issue_3478) {
+ auto detector = wechat_qrcode::WeChatQRCode();
+ std::string image_path = findDataFile("qrcode/issue_3478.png");
+ Mat src = imread(image_path, IMREAD_GRAYSCALE);
+ ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
+ std::vector<std::string> outs = detector.detectAndDecode(src);
+ ASSERT_EQ(1, (int) outs.size());
+ ASSERT_EQ(16, (int) outs[0].size());
+ ASSERT_EQ("KFCVW50 ", outs[0]);
+}
+
} // namespace
} // namespace opencv_test