composite: EANX/UPCA/UPCE_CC addongap (option_2) not being passed to linear

This commit is contained in:
gitlost 2020-08-05 00:14:11 +01:00
parent 04593ebc85
commit b440692ee3
3 changed files with 161 additions and 7 deletions

View File

@ -1521,6 +1521,7 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l
linear = ZBarcode_Create(); /* Symbol contains the 2D component and Linear contains the rest */
linear->symbology = symbol->symbology;
linear->option_2 = symbol->option_2;
linear->debug = symbol->debug;
if (linear->symbology != BARCODE_GS1_128_CC) {

View File

@ -2265,8 +2265,7 @@ static void test_encodation_10(int index, int generate, int debug) {
testFinish();
}
static void test_encodation_11(int index, int generate, int debug)
{
static void test_encodation_11(int index, int generate, int debug) {
testStart("");
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise
@ -2649,9 +2648,162 @@ static void test_encodation_11(int index, int generate, int debug)
testFinish();
}
static void test_addongap(int index, int generate, int debug) {
testStart("");
int do_bwipp = (debug & ZINT_DEBUG_TEST_BWIPP) && testUtilHaveGhostscript(); // Only do BWIPP test if asked, too slow otherwise
int ret;
struct item {
int symbology;
int option_1;
int option_2;
char *data;
int ret;
int expected_rows;
int expected_width;
char *comment;
char *expected;
};
// Verified via bwipp_dump.ps against BWIPP
struct item data[] = {
/* 0*/ { BARCODE_EANX_CC, 1, -1, "1234567+12", 0, 8, 99, "EAN-8 default 7 gap",
"100100011111001101010011000111100010110011001101100111100001011101001101000000000000000000000000000"
"100000111001011001010111000101111000100010001000001001011110011101011101000000000000000000000000000"
"110011010010000001010110000110100111000111101100011001100110011101011001000000000000000000000000000"
"111110001010011001010010000111000010111001101110001101110100011101010001000000000000000000000000000"
"000010000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000"
"000100000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000"
"000010000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000"
"000010100110010010011011110101000110101010011101010000100010011100101010000000101100110010100100110"
},
/* 1*/ { BARCODE_EANX_CC, 1, 8, "1234567+12", 0, 8, 100, "EAN-8 8 gap",
"1001000111110011010100110001111000101100110011011001111000010111010011010000000000000000000000000000"
"1000001110010110010101110001011110001000100010000010010111100111010111010000000000000000000000000000"
"1100110100100000010101100001101001110001111011000110011001100111010110010000000000000000000000000000"
"1111100010100110010100100001110000101110011011100011011101000111010100010000000000000000000000000000"
"0000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000"
"0001000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000"
"0000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000"
"0000101001100100100110111101010001101010100111010100001000100111001010100000000101100110010100100110"
},
/* 2*/ { BARCODE_EANX_CC, 1, -1, "123456789012+12345", 0, 7, 153, "EAN-13 default 7 gap",
"110110111011110011010011100111000100010011101001110100100010110000011001111001111010001011011000101000000000000000000000000000000000000000000000000000000"
"110110110011000100011100100111001100011100101001100100100100011111011001111010010100000011001000101000000000000000000000000000000000000000000000000000000"
"110110100011101111101011000100001010111100001001100110100001100010011101011111011000001011101000101000000000000000000000000000000000000000000000000000000"
"000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000"
"001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000"
"000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000"
"000101001001101111010011101011000100001010010001010101001000111010011100101100110110110010010001010000000101101100110100100110101000010101000110101100010"
},
/* 3*/ { BARCODE_EANX_CC, 1, 9, "123456789012+12345", 0, 7, 155, "EAN-13 9 gap",
"11011011101111001101001110011100010001001110100111010010001011000001100111100111101000101101100010100000000000000000000000000000000000000000000000000000000"
"11011011001100010001110010011100110001110010100110010010010001111101100111101001010000001100100010100000000000000000000000000000000000000000000000000000000"
"11011010001110111110101100010000101011110000100110011010000110001001110101111101100000101110100010100000000000000000000000000000000000000000000000000000000"
"00010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000"
"00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000"
"00010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000"
"00010100100110111101001110101100010000101001000101010100100011101001110010110011011011001001000101000000000101101100110100100110101000010101000110101100010"
},
/* 4*/ { BARCODE_UPCA_CC, 1, -1, "12345678901+12345", 0, 7, 155, "UPC-A default 9 gap",
"11011011101111001101001110011100010001001110100111010010001011000001100111100111101000101101100010100000000000000000000000000000000000000000000000000000000"
"11011011001100010001110010011100110001110010100110010010010001111101100111101001010000001100100010100000000000000000000000000000000000000000000000000000000"
"11011010001110111110101100010000101011110000100110011010000110001001110101111101100000101110100010100000000000000000000000000000000000000000000000000000000"
"00010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000"
"00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000"
"00010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000"
"00010100110010010011011110101000110110001010111101010100010010010001110100111001011001101101100101000000000101101100110100100110101000010101000110101100010"
},
/* 5*/ { BARCODE_UPCA_CC, 1, 10, "12345678901+12345", 0, 7, 156, "UPC-A 10 gap",
"110110111011110011010011100111000100010011101001110100100010110000011001111001111010001011011000101000000000000000000000000000000000000000000000000000000000"
"110110110011000100011100100111001100011100101001100100100100011111011001111010010100000011001000101000000000000000000000000000000000000000000000000000000000"
"110110100011101111101011000100001010111100001001100110100001100010011101011111011000001011101000101000000000000000000000000000000000000000000000000000000000"
"000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000"
"001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000"
"000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000"
"000101001100100100110111101010001101100010101111010101000100100100011101001110010110011011011001010000000000101101100110100100110101000010101000110101100010"
},
/* 6*/ { BARCODE_UPCE_CC, 1, -1, "1234567+12", 0, 9, 82, "UPC-E default 7 gap",
"1101100110111011101011110001101111110110010011110101001000000000000000000000000000"
"1101101110101110011110011001001100110000100011100101001000000000000000000000000000"
"1101101100100101111010000001101000001110100011101101001000000000000000000000000000"
"1101101000110010010001111101011000011001111011101001001000000000000000000000000000"
"1101001000110010000010011001101001000110000011101001101000000000000000000000000000"
"0001000000000000000000000000000000000000000000000000010000000000000000000000000000"
"0010000000000000000000000000000000000000000000000000001000000000000000000000000000"
"0001000000000000000000000000000000000000000000000000010000000000000000000000000000"
"0001010010011011110101000110111001000010100100010101010000000101100110010100100110"
},
/* 7*/ { BARCODE_UPCE_CC, 1, 12, "1234567+12", 0, 9, 87, "UPC-E 12 gap",
"110110011011101110101111000110111111011001001111010100100000000000000000000000000000000"
"110110111010111001111001100100110011000010001110010100100000000000000000000000000000000"
"110110110010010111101000000110100000111010001110110100100000000000000000000000000000000"
"110110100011001001000111110101100001100111101110100100100000000000000000000000000000000"
"110100100011001000001001100110100100011000001110100110100000000000000000000000000000000"
"000100000000000000000000000000000000000000000000000001000000000000000000000000000000000"
"001000000000000000000000000000000000000000000000000000100000000000000000000000000000000"
"000100000000000000000000000000000000000000000000000001000000000000000000000000000000000"
"000101001001101111010100011011100100001010010001010101000000000000101100110010100100110"
},
};
int data_size = ARRAY_SIZE(data);
char bwipp_buf[8192];
char bwipp_msg[1024];
char *composite = "[91]12";
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug);
assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data);
int composite_length = strlen(composite);
ret = ZBarcode_Encode(symbol, (const unsigned char *) composite, composite_length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
if (generate) {
printf(" /*%3d*/ { %s, %d, %d, \"%s\", %s, %d, %d, \"%s\",\n",
i, testUtilBarcodeName(data[i].symbology), data[i].option_1, data[i].option_2, data[i].data,
testUtilErrorName(data[i].ret), symbol->rows, symbol->width, data[i].comment);
testUtilModulesDump(symbol, " ", "\n");
printf(" },\n");
} else {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d %s symbol->rows %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d %s symbol->width %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), symbol->width, data[i].expected_width, data[i].data);
if (ret == 0) {
int width, row;
ret = testUtilModulesCmp(symbol, data[i].expected, &width, &row);
assert_zero(ret, "i:%d %s testUtilModulesCmp ret %d != 0 width %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, width, row, data[i].data);
if (do_bwipp && testUtilCanBwipp(symbol->symbology, data[i].option_1, data[i].option_2, -1, debug)) {
ret = testUtilBwipp(symbol, data[i].option_1, data[i].option_2, -1, composite, composite_length, symbol->primary, bwipp_buf, sizeof(bwipp_buf));
assert_zero(ret, "i:%d %s testUtilBwipp ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), ret);
ret = testUtilBwippCmp(symbol, bwipp_msg, bwipp_buf, data[i].expected);
assert_zero(ret, "i:%d %s testUtilBwippCmp %d != 0 %s\n actual: %s\nexpected: %s\n",
i, testUtilBarcodeName(data[i].symbology), ret, bwipp_msg, bwipp_buf, data[i].expected);
}
}
}
ZBarcode_Delete(symbol);
}
testFinish();
}
// #181 Christian Hartlage OSS-Fuzz
static void test_fuzz(int index, int debug)
{
static void test_fuzz(int index, int debug) {
testStart("");
int ret;
@ -2711,6 +2863,7 @@ int main(int argc, char *argv[]) {
{ "test_encodation_0", test_encodation_0, 1, 1, 1 },
{ "test_encodation_10", test_encodation_10, 1, 1, 1 },
{ "test_encodation_11", test_encodation_11, 1, 1, 1 },
{ "test_addongap", test_addongap, 1, 1, 1 },
{ "test_fuzz", test_fuzz, 1, 0, 1 },
};

View File

@ -1597,13 +1597,13 @@ static char *testUtilBwippName(int symbology, int option_1, int option_2, int op
{ "", -1, 127, 0, 0, 0, 0, 0, },
{ "aztecrune", BARCODE_AZRUNE, 128, 0, 0, 0, 0, 0, },
{ "code32", BARCODE_CODE32, 129, 0, 0, 0, 0, 0, },
{ "ean13composite", BARCODE_EANX_CC, 130, 1, 0, 0, 72 /*linear_row_height*/, 1 /*gs1_cvt*/, },
{ "ean13composite", BARCODE_EANX_CC, 130, 1, 1, 0, 72 /*linear_row_height*/, 1 /*gs1_cvt*/, },
{ "gs1-128composite", BARCODE_GS1_128_CC, 131, 1, 0, 0, 36, 1, },
{ "databaromnicomposite", BARCODE_DBAR_OMN_CC, 132, 1, 0, 0, 33, 1, },
{ "databarlimitedcomposite", BARCODE_DBAR_LTD_CC, 133, 1, 0, 0, 0, 1, },
{ "databarexpandedcomposite", BARCODE_DBAR_EXP_CC, 134, 1, 1, 0, 0, 1, },
{ "upcacomposite", BARCODE_UPCA_CC, 135, 1, 0, 0, 72, 1, },
{ "upcecomposite", BARCODE_UPCE_CC, 136, 1, 0, 0, 72, 1, },
{ "upcacomposite", BARCODE_UPCA_CC, 135, 1, 1, 0, 72, 1, },
{ "upcecomposite", BARCODE_UPCE_CC, 136, 1, 1, 0, 72, 1, },
{ "databarstackedcomposite", BARCODE_DBAR_STK_CC, 137, 1, 0, 0, 0, 1, },
{ "databarstackedomnicomposite", BARCODE_DBAR_OMNSTK_CC, 138, 1, 0, 0, 0, 1, },
{ "databarexpandedstackedcomposite", BARCODE_DBAR_EXPSTK_CC, 139, 1, 1, 0, 0, 1, },