From 5acbffff0d88a41e3c557d93e48507e58ba1376d Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Tue, 11 Apr 2017 09:26:39 +0100 Subject: [PATCH] Consistently throw an error if data does not fit in specified size symbol See ticket #57 --- backend/code1.c | 6 ++++++ backend/dmatrix.c | 5 ++--- backend/gridmtx.c | 3 ++- backend/hanxin.c | 5 +++++ backend/qr.c | 8 ++++++++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/backend/code1.c b/backend/code1.c index c48bb71f..62b14830 100644 --- a/backend/code1.c +++ b/backend/code1.c @@ -1425,6 +1425,7 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length) { data_length = c1_encode(symbol, source, data, length); if (data_length == 0) { + strcpy(symbol->errtxt, "Input data is too long"); return ZINT_ERROR_TOO_LONG; } @@ -1437,6 +1438,11 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length) { if (symbol->option_2 > size) { 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++) { data[i] = 129; /* Pad */ diff --git a/backend/dmatrix.c b/backend/dmatrix.c index 3a3deb19..9c8856f3 100644 --- a/backend/dmatrix.c +++ b/backend/dmatrix.c @@ -1183,9 +1183,8 @@ int data_matrix_200(struct zint_symbol *symbol, const unsigned char source[], co if (calcsize > optionsize) { symbolsize = calcsize; if (optionsize != -1) { - /* flag an error */ - error_number = ZINT_WARN_INVALID_OPTION; - strcpy(symbol->errtxt, "Data does not fit in selected symbol size (E12)"); + strcpy(symbol->errtxt, "Input too long for selected symbol size"); + return ZINT_ERROR_TOO_LONG; } } diff --git a/backend/gridmtx.c b/backend/gridmtx.c index 0dd394c1..992f259c 100644 --- a/backend/gridmtx.c +++ b/backend/gridmtx.c @@ -1141,7 +1141,8 @@ int grid_matrix(struct zint_symbol *symbol, const unsigned char source[], int le if (symbol->option_2 > min_layers) { layers = symbol->option_2; } else { - layers = min_layers; + strcpy(symbol->errtxt, "Input data too long for selected symbol size"); + return ZINT_ERROR_TOO_LONG; } } diff --git a/backend/hanxin.c b/backend/hanxin.c index 249b6f15..356b20e5 100644 --- a/backend/hanxin.c +++ b/backend/hanxin.c @@ -1448,6 +1448,11 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length if (symbol->option_2 > version) { 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 */ diff --git a/backend/qr.c b/backend/qr.c index 4585f568..a2489c62 100644 --- a/backend/qr.c +++ b/backend/qr.c @@ -1632,6 +1632,11 @@ int qr_code(struct zint_symbol *symbol, const unsigned char source[], int length version = symbol->option_2; 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 */ @@ -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 >= autoversion) { version = symbol->option_2; + } else { + strcpy(symbol->errtxt, "Input too long for selected symbol size"); + return ZINT_ERROR_TOO_LONG; } }