Skip to content

Commit

Permalink
Incorrect bit extraction bug in QRcode_encodeMaskMQR() has been fixed…
Browse files Browse the repository at this point in the history
…. (issue fukuchi#25) (Thanks to vlad417)
  • Loading branch information
fukuchi committed Nov 8, 2012
1 parent 80b60e2 commit cb3e8ec
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
8 changes: 6 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
2012.11.8 Kentaro FUKUCHI <kentaro@fukuchi.org>
* qrinput.c:
- Memory leak bug has been fixed. (issue #25) (Thanks to chisj)
* tests/test_qrinput.c:
- Memory leak bug has been fixed. (issue #24) (Thanks to chisj)
* qrencode.c:
- Incorrect bit extraction bug in QRcode_encodeMaskMQR() has been fixed.
(issue #25) (Thanks to vlad417)
* tests/test_qrencode.c:
- Added NUL checks for malloc-related bugs using failmalloc.
- Added a new test for issue #25. (Thanks to vlad417)

2012.10.17 Kentaro FUKUCHI <kentaro@fukuchi.org>
[3.4]
Expand Down
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,5 @@ Lennart Poettering (mezcalero)
- Improved text art patch
Yann Droneaud - Improved input validation patch
Shigeyuki Hirai, Paul Janssens, wangsai, Gavan Fantom, Matthew Baker, Rob Ryan,
Fred Steinhaeuser, Terry Burton
Fred Steinhaeuser, Terry Burton, chisj, vlad417
- bug report / suggestion
2 changes: 1 addition & 1 deletion qrencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ __STATIC QRcode *QRcode_encodeMaskMQR(QRinput *input, int mask)
for(i=0; i<raw->dataLength + raw->eccLength; i++) {
code = MQRraw_getCode(raw);
if(raw->oddbits && i == raw->dataLength - 1) {
bit = 1 << raw->oddbits;
bit = 1 << (raw->oddbits - 1);
for(j=0; j<raw->oddbits; j++) {
p = FrameFiller_next(filler);
if(p == NULL) goto EXIT;
Expand Down
42 changes: 42 additions & 0 deletions tests/test_qrencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ static const char decodeAnTable[45] = {
'+', '-', '.', '/', ':'
};

typedef struct {
char *str;
int version;
QRecLevel level;
QRencodeMode hint;
int casesensitive;
} TestString;
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))

#define drand(__scale__) ((__scale__) * (double)rand() / ((double)RAND_MAX + 1.0))

int inputSize(QRinput *input)
Expand Down Expand Up @@ -818,6 +827,38 @@ void test_decodeShortMQR(void)
testFinish();
}

void test_oddBitCalcMQR(void)
{
/* test issue #25 (odd bits calculation bug) */
/* test pattern contributed by vlad417 */
TestString tests[] = {
{"46194", 1, QR_ECLEVEL_L, QR_MODE_8, 1},
{"WBA5Y47YPQQ", 3, QR_ECLEVEL_L, QR_MODE_8, 1}
};
QRcode *qrcode;
QRdata *qrdata;
int i;

testStart("Odd bits calculation bug checking (MQR).");

for(i=0; i<_countof(tests); i++) {
qrcode = QRcode_encodeStringMQR(tests[i].str,
tests[i].version,
tests[i].level,
tests[i].hint,
tests[i].casesensitive);
assert_nonnull(qrcode, "Failed to encode: %s\n", tests[i].str);
if(qrcode == NULL) continue;
qrdata = QRcode_decodeMQR(qrcode);
assert_nonnull(qrdata, "Failed to decode.\n");
assert_zero(strcmp((char *)qrdata->data, tests[i].str), "Decoded data (%s) mismatched (%s)\n", (char *)qrdata->data, tests[i].str);
if(qrdata != NULL) QRdata_free(qrdata);
QRcode_free(qrcode);
}

testFinish();
}

void test_mqrencode(void)
{
char *str = "MICROQR";
Expand Down Expand Up @@ -915,6 +956,7 @@ int main(void)
test_formatInfoMQR();
test_encodeTooLongMQR();
test_decodeShortMQR();
test_oddBitCalcMQR();
test_mqrencode();
test_apiversion();

Expand Down

0 comments on commit cb3e8ec

Please sign in to comment.