about summary refs log tree commit diff
path: root/editor
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-04-01 02:46:47 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-04-01 02:46:47 +0000
commit5311fdef6ed014e3b97cec4956cc25c40dc5f3c8 (patch)
treef067df11d38ec9f93e528bbb65bb1bf727a712ba /editor
parent19646f8073a34247baef1a8a012edcda1d0490dd (diff)
downloadnetpbm-mirror-5311fdef6ed014e3b97cec4956cc25c40dc5f3c8.tar.gz
netpbm-mirror-5311fdef6ed014e3b97cec4956cc25c40dc5f3c8.tar.xz
netpbm-mirror-5311fdef6ed014e3b97cec4956cc25c40dc5f3c8.zip
Limit size of pnmconvol invocation parameters
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1169 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'editor')
-rw-r--r--editor/pnmsmooth.c23
1 files changed, 23 insertions, 0 deletions
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);