1
0
mirror of https://git.code.sf.net/p/zint/code synced 2026-05-01 11:45:29 +00:00

GS1SE: fix bug in allowing initial GSs in GS1RAW_MODE in composites

This commit is contained in:
gitlost
2026-02-26 16:34:59 +00:00
parent 0a8a79fa6c
commit 9ef5bc7298
2 changed files with 57 additions and 48 deletions

View File

@@ -1710,23 +1710,25 @@ static int gs1se_verify(struct zint_symbol *symbol, const unsigned char source[]
/* Need to add initial carets */ /* Need to add initial carets */
local_source_buf[0] = '^'; local_source_buf[0] = '^';
local_length = 1; local_length = 1;
/* Linear GSs */
if (symbol->primary[0] == '\x1D') { /* Allow initial GS */ if (symbol->primary[0] == '\x1D') { /* Allow initial GS */
gs1se_gs_caret_sub(ZCUCP(symbol->primary + 1), primary_len - 1, local_source_buf + 1); /* Linear GSs */ gs1se_gs_caret_sub(ZCUCP(symbol->primary + 1), primary_len - 1, local_source_buf + local_length);
local_length += primary_len - 1; local_length += primary_len - 1;
} else { } else {
gs1se_gs_caret_sub(ZCUCP(symbol->primary), primary_len, local_source_buf + 1); /* Linear GSs */ gs1se_gs_caret_sub(ZCUCP(symbol->primary), primary_len, local_source_buf + local_length);
local_length += primary_len; local_length += primary_len;
} }
local_source_buf[local_length++] = '|'; local_source_buf[local_length++] = '|';
local_source_buf[local_length++] = '^'; local_source_buf[local_length++] = '^';
/* CC GSs */
if (source[0] == '\x1D') { /* Allow initial GS */ if (source[0] == '\x1D') { /* Allow initial GS */
gs1se_gs_caret_sub(source + 1, length - 1, local_source_buf + primary_len + 3); /* CC GSs */ gs1se_gs_caret_sub(source + 1, length - 1, local_source_buf + local_length);
local_length += length - 1; local_length += length - 1;
} else { } else {
gs1se_gs_caret_sub(source, length, local_source_buf + primary_len + 3); /* CC GSs */ gs1se_gs_caret_sub(source, length, local_source_buf + local_length);
local_length += length; local_length += length;
} }
linear_len = primary_len; linear_len = primary_len - (symbol->primary[0] == '\x1D'); /* Exclude initial GS if any */
} else { } else {
memcpy(local_source_buf, symbol->primary, primary_len); memcpy(local_source_buf, symbol->primary, primary_len);
local_source_buf[primary_len] = '|'; local_source_buf[primary_len] = '|';

View File

@@ -1316,49 +1316,56 @@ static void test_gs1_128_dbar_exp(const testCtx *const p_ctx) {
/* 66*/ { BARCODE_GS1_128_CC, -1, "[01]12345678901231", "[90]12[34", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" }, /* 66*/ { BARCODE_GS1_128_CC, -1, "[01]12345678901231", "[90]12[34", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" },
/* 67*/ { BARCODE_GS1_128_CC, -1, "https://example.com/01/12345678901231", "[20]12", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" }, /* 67*/ { BARCODE_GS1_128_CC, -1, "https://example.com/01/12345678901231", "[20]12", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" },
/* 68*/ { BARCODE_DBAR_EXP, -1, "[01]12345678901231", "", 0, "" }, /* 68*/ { BARCODE_DBAR_EXP, -1, "[01]12345678901231", "", 0, "" },
/* 69*/ { BARCODE_DBAR_EXP, -1, "[01]12345678901231[10]123[11]12345", "", ZINT_ERROR_INVALID_DATA, "Error 268: AI (11) value is too short" }, /* 69*/ { BARCODE_DBAR_EXP, -1, "^0112345678901231", "", 0, "" },
/* 70*/ { BARCODE_DBAR_EXP, -1, "[01]12345678901231[10]123[11]12345A", "", ZINT_ERROR_INVALID_DATA, "Error 267: AI (11): A non-digit character was found where a digit is expected. (11)12345|A|" }, /* 70*/ { BARCODE_DBAR_EXP, GS1RAW_MODE, "0112345678901231", "", 0, "" },
/* 71*/ { BARCODE_DBAR_EXP, -1, "011234567890121", "", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" }, /* 71*/ { BARCODE_DBAR_EXP, GS1RAW_MODE, "\0350112345678901231", "", 0, "" },
/* 72*/ { BARCODE_DBAR_EXP, -1, "[10]", "", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" }, /* 72*/ { BARCODE_DBAR_EXP, -1, "[01]12345678901231[10]123[11]12345", "", ZINT_ERROR_INVALID_DATA, "Error 268: AI (11) value is too short" },
/* 73*/ { BARCODE_DBAR_EXP, -1, "[2]1", "", ZINT_ERROR_INVALID_DATA, "Error 268: Unrecognised AI: 2" }, /* 73*/ { BARCODE_DBAR_EXP, -1, "[01]12345678901231[10]123[11]12345A", "", ZINT_ERROR_INVALID_DATA, "Error 267: AI (11): A non-digit character was found where a digit is expected. (11)12345|A|" },
/* 74*/ { BARCODE_DBAR_EXP, -1, "[]1", "", ZINT_ERROR_INVALID_DATA, "Error 268: Unrecognised AI: " }, /* 74*/ { BARCODE_DBAR_EXP, -1, "011234567890121", "", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" },
/* 75*/ { BARCODE_DBAR_EXP, -1, "[]", "", ZINT_ERROR_INVALID_DATA, "Error 268: Unrecognised AI: " }, /* 75*/ { BARCODE_DBAR_EXP, -1, "[10]", "", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" },
/* 76*/ { BARCODE_DBAR_EXP, -1, "[20]12[]", "", ZINT_ERROR_INVALID_DATA, "Error 268: Unrecognised AI: " }, /* 76*/ { BARCODE_DBAR_EXP, -1, "[2]1", "", ZINT_ERROR_INVALID_DATA, "Error 268: Unrecognised AI: 2" },
/* 77*/ { BARCODE_DBAR_EXP, -1, "[90]12]34", "", ZINT_ERROR_INVALID_DATA, "Error 267: AI (90): A non-CSET 82 character was found where a CSET 82 character is expected. (90)12|]|34" }, /* 77*/ { BARCODE_DBAR_EXP, -1, "[]1", "", ZINT_ERROR_INVALID_DATA, "Error 268: Unrecognised AI: " },
/* 78*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231[10]123[11]121212", "[21]ABC123[22]12345", 0, "" }, /* 78*/ { BARCODE_DBAR_EXP, -1, "[]", "", ZINT_ERROR_INVALID_DATA, "Error 268: Unrecognised AI: " },
/* 79*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231[10]123[11]1234", "[21]ABC123[22]12345", ZINT_ERROR_INVALID_DATA, "Error 268: AI (11) value is too short" }, /* 79*/ { BARCODE_DBAR_EXP, -1, "[20]12[]", "", ZINT_ERROR_INVALID_DATA, "Error 268: Unrecognised AI: " },
/* 80*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231[10]123[11]123456", "[21]ABC123[22]12345", ZINT_ERROR_INVALID_DATA, "Error 267: AI (11): The date contains an illegal month of the year. (11)12|34|56" }, /* 80*/ { BARCODE_DBAR_EXP, -1, "[90]12]34", "", ZINT_ERROR_INVALID_DATA, "Error 267: AI (90): A non-CSET 82 character was found where a CSET 82 character is expected. (90)12|]|34" },
/* 81*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231[10]123[11]121212", "[21]ABC123[22]12345[30]123456789", ZINT_ERROR_INVALID_DATA, "Error 268: AI (30) value is too long" }, /* 81*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231[10]123[11]121212", "[21]ABC123[22]12345", 0, "" },
/* 82*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231[10]123[11]121212", "[21]ABC123[22]12345[30]1234567A", ZINT_ERROR_INVALID_DATA, "Error 267: AI (30): A non-digit character was found where a digit is expected. (30)1234567|A|" }, /* 82*/ { BARCODE_DBAR_EXP_CC, GS1RAW_MODE, "011234567890123110123\03511121212", "21ABC123\0352212345", 0, "" },
/* 83*/ { BARCODE_DBAR_EXP_CC, -1, "[01]1234567890121\177", "[20]12", ZINT_ERROR_INVALID_DATA, "Error 267: AI (01): A non-digit character was found where a digit is expected. (01)1234567890121|\\x7F|" }, /* 83*/ { BARCODE_DBAR_EXP_CC, GS1RAW_MODE, "\035011234567890123110123\03511121212", "\03521ABC123\0352212345", 0, "" },
/* 84*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231", "[20]1\177", ZINT_ERROR_INVALID_DATA, "Error 267: AI (20): A non-digit character was found where a digit is expected. (20)1|\\x7F|" }, /* 84*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231[10]123[11]1234", "[21]ABC123[22]12345", ZINT_ERROR_INVALID_DATA, "Error 268: AI (11) value is too short" },
/* 85*/ { BARCODE_DBAR_EXP_CC, -1, "[01]1234567890121", "2012", ZINT_ERROR_INVALID_DATA, "Error 268: AI (01) value is too short" }, /* 85*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231[10]123[11]123456", "[21]ABC123[22]12345", ZINT_ERROR_INVALID_DATA, "Error 267: AI (11): The date contains an illegal month of the year. (11)12|34|56" },
/* 86*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231", "2012", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" }, /* 86*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231[10]123[11]121212", "[21]ABC123[22]12345[30]123456789", ZINT_ERROR_INVALID_DATA, "Error 268: AI (30) value is too long" },
/* 87*/ { BARCODE_DBAR_EXP_CC, -1, "[01]1234567890121", "[10]", ZINT_ERROR_INVALID_DATA, "Error 268: AI (01) value is too short" }, /* 87*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231[10]123[11]121212", "[21]ABC123[22]12345[30]1234567A", ZINT_ERROR_INVALID_DATA, "Error 267: AI (30): A non-digit character was found where a digit is expected. (30)1234567|A|" },
/* 88*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231", "[10]", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" }, /* 88*/ { BARCODE_DBAR_EXP_CC, -1, "[01]1234567890121\177", "[20]12", ZINT_ERROR_INVALID_DATA, "Error 267: AI (01): A non-digit character was found where a digit is expected. (01)1234567890121|\\x7F|" },
/* 89*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231", "[2]1", ZINT_ERROR_INVALID_DATA, "Error 268: Unrecognised AI: 2" }, /* 89*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231", "[20]1\177", ZINT_ERROR_INVALID_DATA, "Error 267: AI (20): A non-digit character was found where a digit is expected. (20)1|\\x7F|" },
/* 90*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231", "[]12", ZINT_ERROR_INVALID_DATA, "Error 268: Unrecognised AI: " }, /* 90*/ { BARCODE_DBAR_EXP_CC, -1, "[01]1234567890121", "2012", ZINT_ERROR_INVALID_DATA, "Error 268: AI (01) value is too short" },
/* 91*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231", "[]", ZINT_ERROR_INVALID_DATA, "Error 268: Unrecognised AI: " }, /* 91*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231", "2012", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" },
/* 92*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231", "[90]12]34", ZINT_ERROR_INVALID_DATA, "Error 267: AI (90): A non-CSET 82 character was found where a CSET 82 character is expected. (90)12|]|34" }, /* 92*/ { BARCODE_DBAR_EXP_CC, -1, "[01]1234567890121", "[10]", ZINT_ERROR_INVALID_DATA, "Error 268: AI (01) value is too short" },
/* 93*/ { BARCODE_DBAR_EXPSTK, -1, "[01]12345678901231", "", 0, "" }, /* 93*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231", "[10]", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" },
/* 94*/ { BARCODE_DBAR_EXPSTK, -1, "[01]12345678901231[10]123[11]1234", "", ZINT_ERROR_INVALID_DATA, "Error 268: AI (11) value is too short" }, /* 94*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231", "[2]1", ZINT_ERROR_INVALID_DATA, "Error 268: Unrecognised AI: 2" },
/* 95*/ { BARCODE_DBAR_EXPSTK, -1, "[01]12345678901231[10]123[11]12345A", "", ZINT_ERROR_INVALID_DATA, "Error 267: AI (11): A non-digit character was found where a digit is expected. (11)12345|A|" }, /* 95*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231", "[]12", ZINT_ERROR_INVALID_DATA, "Error 268: Unrecognised AI: " },
/* 96*/ { BARCODE_DBAR_EXPSTK, -1, "[01]1234567890121\177", "", ZINT_ERROR_INVALID_DATA, "Error 267: AI (01): A non-digit character was found where a digit is expected. (01)1234567890121|\\x7F|" }, /* 96*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231", "[]", ZINT_ERROR_INVALID_DATA, "Error 268: Unrecognised AI: " },
/* 97*/ { BARCODE_DBAR_EXPSTK, -1, "[01]1234567890121\200", "", ZINT_ERROR_INVALID_DATA, "Error 267: AI (01): A non-digit character was found where a digit is expected. (01)1234567890121|\\x80|" }, /* 97*/ { BARCODE_DBAR_EXP_CC, -1, "[01]12345678901231", "[90]12]34", ZINT_ERROR_INVALID_DATA, "Error 267: AI (90): A non-CSET 82 character was found where a CSET 82 character is expected. (90)12|]|34" },
/* 98*/ { BARCODE_DBAR_EXPSTK, -1, "011234567890121", "", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" }, /* 98*/ { BARCODE_DBAR_EXPSTK, -1, "[01]12345678901231", "", 0, "" },
/* 99*/ { BARCODE_DBAR_EXPSTK, -1, "[01]", "", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" }, /* 99*/ { BARCODE_DBAR_EXPSTK, -1, "[01]12345678901231[10]123[11]1234", "", ZINT_ERROR_INVALID_DATA, "Error 268: AI (11) value is too short" },
/*100*/ { BARCODE_DBAR_EXPSTK, -1, "[90]12]34", "", ZINT_ERROR_INVALID_DATA, "Error 267: AI (90): A non-CSET 82 character was found where a CSET 82 character is expected. (90)12|]|34" }, /*100*/ { BARCODE_DBAR_EXPSTK, -1, "[01]12345678901231[10]123[11]12345A", "", ZINT_ERROR_INVALID_DATA, "Error 267: AI (11): A non-digit character was found where a digit is expected. (11)12345|A|" },
/*101*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231[10]123[11]121212", "[21]ABC123[22]12345", 0, "" }, /*101*/ { BARCODE_DBAR_EXPSTK, -1, "[01]1234567890121\177", "", ZINT_ERROR_INVALID_DATA, "Error 267: AI (01): A non-digit character was found where a digit is expected. (01)1234567890121|\\x7F|" },
/*102*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231[10]123[11]1234", "[21]ABC123[22]12345", ZINT_ERROR_INVALID_DATA, "Error 268: AI (11) value is too short" }, /*102*/ { BARCODE_DBAR_EXPSTK, -1, "[01]1234567890121\200", "", ZINT_ERROR_INVALID_DATA, "Error 267: AI (01): A non-digit character was found where a digit is expected. (01)1234567890121|\\x80|" },
/*103*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231[10]123[11]123456", "[21]ABC123[22]12345", ZINT_ERROR_INVALID_DATA, "Error 267: AI (11): The date contains an illegal month of the year. (11)12|34|56" }, /*103*/ { BARCODE_DBAR_EXPSTK, -1, "011234567890121", "", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" },
/*104*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231[10]123[11]121212", "[21]ABC123[22]12345[30]123456789", ZINT_ERROR_INVALID_DATA, "Error 268: AI (30) value is too long" }, /*104*/ { BARCODE_DBAR_EXPSTK, -1, "[01]", "", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" },
/*105*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231[10]123[11]121212", "[21]ABC123[22]12345[30]1234567A", ZINT_ERROR_INVALID_DATA, "Error 267: AI (30): A non-digit character was found where a digit is expected. (30)1234567|A|" }, /*105*/ { BARCODE_DBAR_EXPSTK, -1, "[90]12]34", "", ZINT_ERROR_INVALID_DATA, "Error 267: AI (90): A non-CSET 82 character was found where a CSET 82 character is expected. (90)12|]|34" },
/*106*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]1234567890121", "[20]1\177", ZINT_ERROR_INVALID_DATA, "Error 268: AI (01) value is too short" }, /*106*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231[10]123[11]121212", "[21]ABC123[22]12345", 0, "" },
/*107*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231", "[20]1\200", ZINT_ERROR_INVALID_DATA, "Error 267: AI (20): A non-digit character was found where a digit is expected. (20)1|\\x80|" }, /*107*/ { BARCODE_DBAR_EXPSTK_CC, GS1RAW_MODE, "011234567890123110123\03511121212", "21ABC123\0352212345", 0, "" },
/*108*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231", "2012", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" }, /*108*/ { BARCODE_DBAR_EXPSTK_CC, GS1RAW_MODE, "\035011234567890123110123\03511121212", "21ABC123\0352212345", 0, "" },
/*109*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]1234567890121", "[235]", ZINT_ERROR_INVALID_DATA, "Error 268: AI (01) value is too short" }, /*109*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231[10]123[11]1234", "[21]ABC123[22]12345", ZINT_ERROR_INVALID_DATA, "Error 268: AI (11) value is too short" },
/*110*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231", "[235]", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" }, /*110*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231[10]123[11]123456", "[21]ABC123[22]12345", ZINT_ERROR_INVALID_DATA, "Error 267: AI (11): The date contains an illegal month of the year. (11)12|34|56" },
/*111*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231", "[90]12]34", ZINT_ERROR_INVALID_DATA, "Error 267: AI (90): A non-CSET 82 character was found where a CSET 82 character is expected. (90)12|]|34" }, /*111*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231[10]123[11]121212", "[21]ABC123[22]12345[30]123456789", ZINT_ERROR_INVALID_DATA, "Error 268: AI (30) value is too long" },
/*112*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231[10]123[11]121212", "[21]ABC123[22]12345[30]1234567A", ZINT_ERROR_INVALID_DATA, "Error 267: AI (30): A non-digit character was found where a digit is expected. (30)1234567|A|" },
/*113*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]1234567890121", "[20]1\177", ZINT_ERROR_INVALID_DATA, "Error 268: AI (01) value is too short" },
/*114*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231", "[20]1\200", ZINT_ERROR_INVALID_DATA, "Error 267: AI (20): A non-digit character was found where a digit is expected. (20)1|\\x80|" },
/*115*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231", "2012", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" },
/*116*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]1234567890121", "[235]", ZINT_ERROR_INVALID_DATA, "Error 268: AI (01) value is too short" },
/*117*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231", "[235]", ZINT_ERROR_INVALID_DATA, "Error 268: Failed to parse AI data" },
/*118*/ { BARCODE_DBAR_EXPSTK_CC, -1, "[01]12345678901231", "[90]12]34", ZINT_ERROR_INVALID_DATA, "Error 267: AI (90): A non-CSET 82 character was found where a CSET 82 character is expected. (90)12|]|34" },
}; };
const int data_size = ARRAY_SIZE(data); const int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;