From 5311fdef6ed014e3b97cec4956cc25c40dc5f3c8 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Thu, 1 Apr 2010 02:46:47 +0000 Subject: Limit size of pnmconvol invocation parameters git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1169 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- editor/pnmsmooth.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'editor/pnmsmooth.c') 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); -- cgit 1.4.1