[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master e59ab11: Stricter checking for polygon point l
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master e59ab11: Stricter checking for polygon point list argument of imgcrop |
Date: |
Tue, 3 Jan 2017 15:58:12 +0000 (UTC) |
branch: master
commit e59ab1137b9d97d780ab116d96abba725f4ae882
Author: Vladimir Markelov <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
Stricter checking for polygon point list argument of imgcrop
The main idea is that every point is the floating number separated with ';'
or ',' or space from the next number. So, after converting a string to a
number the pointer should point to one of separators. Otherwise the
floating point has some invalid characters.
Summary of rules of a good number (after conversion):
1. Pointer can stop at the end of line (check for '\0').
2. Pointer can stop at whitespace (check for isspace).
3. Pointer can stop at a separator (check for ':' and ',').
Why check for space is considered to be OK. A user can set argument list in
two ways:
1. Without any space, like "polygon=1.1,0.1:1.2,2.0".
2. And using spaces to make it more readable, like:
"polygon='1.0,1.5 : 1.5,2.6'".
This fixes bug #48978.
---
bin/imgcrop/crop.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/bin/imgcrop/crop.c b/bin/imgcrop/crop.c
index e55b521..62b1f93 100644
--- a/bin/imgcrop/crop.c
+++ b/bin/imgcrop/crop.c
@@ -222,6 +222,18 @@ polygonparser(struct imgcropparams *p)
error(EXIT_FAILURE, 0, "%s could not be parsed as a floating "
"point number", tailptr);
+ /* Check if there are no extra characters in the number, for
+ example we don't have a case like `1.00132.17', or
+ 1.01i:2.0. Such errors are not uncommon when typing large
+ numbers, and if ignored, they can lead to unpredictable
+ results, so its best to abort and inform the user. */
+ if( *tailptr!='\0'
+ && !isspace(*tailptr)
+ && strchr(":,", *tailptr)==NULL )
+ error(EXIT_FAILURE, 0, "'%s' is an invalid floating point number "
+ "sequence in the value to the `--polygon' option, error "
+ "detected at '%s'", pt, tailptr);
+
/* If this was the second dimension, then put the values
into the linked list: */
if(dim==1)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master e59ab11: Stricter checking for polygon point list argument of imgcrop,
Mohammad Akhlaghi <=