mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Consistently throw an error if data does not fit in specified size symbol
See ticket #57
This commit is contained in:
parent
ff6995070b
commit
5acbffff0d
@ -1425,6 +1425,7 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length) {
|
|||||||
data_length = c1_encode(symbol, source, data, length);
|
data_length = c1_encode(symbol, source, data, length);
|
||||||
|
|
||||||
if (data_length == 0) {
|
if (data_length == 0) {
|
||||||
|
strcpy(symbol->errtxt, "Input data is too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1438,6 +1439,11 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length) {
|
|||||||
size = symbol->option_2;
|
size = symbol->option_2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((symbol-> option_2 != 0) && (symbol->option_2 < size)) {
|
||||||
|
strcpy(symbol->errtxt, "Input too long for selected symbol size");
|
||||||
|
return ZINT_ERROR_TOO_LONG;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = data_length; i < c1_data_length[size - 1]; i++) {
|
for (i = data_length; i < c1_data_length[size - 1]; i++) {
|
||||||
data[i] = 129; /* Pad */
|
data[i] = 129; /* Pad */
|
||||||
}
|
}
|
||||||
|
@ -1183,9 +1183,8 @@ int data_matrix_200(struct zint_symbol *symbol, const unsigned char source[], co
|
|||||||
if (calcsize > optionsize) {
|
if (calcsize > optionsize) {
|
||||||
symbolsize = calcsize;
|
symbolsize = calcsize;
|
||||||
if (optionsize != -1) {
|
if (optionsize != -1) {
|
||||||
/* flag an error */
|
strcpy(symbol->errtxt, "Input too long for selected symbol size");
|
||||||
error_number = ZINT_WARN_INVALID_OPTION;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
strcpy(symbol->errtxt, "Data does not fit in selected symbol size (E12)");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1141,7 +1141,8 @@ int grid_matrix(struct zint_symbol *symbol, const unsigned char source[], int le
|
|||||||
if (symbol->option_2 > min_layers) {
|
if (symbol->option_2 > min_layers) {
|
||||||
layers = symbol->option_2;
|
layers = symbol->option_2;
|
||||||
} else {
|
} else {
|
||||||
layers = min_layers;
|
strcpy(symbol->errtxt, "Input data too long for selected symbol size");
|
||||||
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1449,6 +1449,11 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length
|
|||||||
version = symbol->option_2;
|
version = symbol->option_2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((symbol->option_2 != 0) && (symbol->option_2 < version)) {
|
||||||
|
strcpy(symbol->errtxt, "Input too long for selected symbol size");
|
||||||
|
return ZINT_ERROR_TOO_LONG;
|
||||||
|
}
|
||||||
|
|
||||||
/* If there is spare capacity, increase the level of ECC */
|
/* If there is spare capacity, increase the level of ECC */
|
||||||
|
|
||||||
if ((ecc_level == 1) && (codewords < hx_data_codewords_L2[version - 1])) {
|
if ((ecc_level == 1) && (codewords < hx_data_codewords_L2[version - 1])) {
|
||||||
|
@ -1632,6 +1632,11 @@ int qr_code(struct zint_symbol *symbol, const unsigned char source[], int length
|
|||||||
version = symbol->option_2;
|
version = symbol->option_2;
|
||||||
est_binlen = getBinaryLength(symbol->option_2, mode, jisdata, length, gs1, symbol->eci);
|
est_binlen = getBinaryLength(symbol->option_2, mode, jisdata, length, gs1, symbol->eci);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (symbol->option_2 < version) {
|
||||||
|
strcpy(symbol->errtxt, "Input too long for selected symbol size");
|
||||||
|
return ZINT_ERROR_TOO_LONG;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure maxium error correction capacity */
|
/* Ensure maxium error correction capacity */
|
||||||
@ -2791,6 +2796,9 @@ int microqr(struct zint_symbol *symbol, const unsigned char source[], int length
|
|||||||
if ((symbol->option_2 >= 1) && (symbol->option_2 <= 4)) {
|
if ((symbol->option_2 >= 1) && (symbol->option_2 <= 4)) {
|
||||||
if (symbol->option_2 >= autoversion) {
|
if (symbol->option_2 >= autoversion) {
|
||||||
version = symbol->option_2;
|
version = symbol->option_2;
|
||||||
|
} else {
|
||||||
|
strcpy(symbol->errtxt, "Input too long for selected symbol size");
|
||||||
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user