diff options
-rw-r--r-- | doc/HISTORY | 4 | ||||
-rw-r--r-- | editor/pnmsmooth.c | 23 |
2 files changed, 27 insertions, 0 deletions
diff --git a/doc/HISTORY b/doc/HISTORY index c953cc4e..86e3d372 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -12,6 +12,10 @@ not yet BJH Release 10.51.00 pnmsmooth: Don't display pnmconvol messages (i.e. run pnmconvol with -quiet). + pnmsmooth: Fail politely when convolution matrix is so + large as to bust the system's program parameter size limit + on the invocation of pnmconvol. + pnmsmooth: fix arithmetic overflow with absurdly large convolution matrix dimensions. Thanks Prophet of the Way <afu@wta.att.ne.jp>. diff --git a/editor/pnmsmooth.c b/editor/pnmsmooth.c index eabe479e..92796814 100644 --- a/editor/pnmsmooth.c +++ b/editor/pnmsmooth.c @@ -196,11 +196,33 @@ makeConvolutionKernel(unsigned int const cols, assert(cursor < maxOptSize); matrix[cursor] = '\0'; } + return matrix; } +static void +validateMatrixOptSize(unsigned int const rows, + unsigned int const cols) { + + /* If the user accidentally specifies absurdly large values for the + convolution matrix size, the failure mode can be a confusing message + resulting from the 'pnmconvol' arguments being too large. To try + to be more polite in that case, we apply an arbitrary limit on the + size of the option here. + */ + + if (rows * cols > 5000) + pm_error("Convolution matrix dimensions %u x %u are too large " + "to be useful, so we assume you made a mistake. " + "We refuse to use numbers this large because they might " + "cause excessive resource use that would cause failures " + "whose cause would not be obvious to you", cols, rows); +} + + + int main(int argc, const char ** argv) { @@ -212,6 +234,7 @@ main(int argc, const char ** argv) { parseCommandLine(argc, argv, &cmdline); validateComputableDimensions(cmdline.width, cmdline.height); + validateMatrixOptSize(cmdline.width, cmdline.height); matrixOptValue = makeConvolutionKernel(cmdline.width, cmdline.height); |