Skip parsing invalid squares (#599)
authorFabian Fichter <ianfab@users.noreply.github.com>
Sun, 19 Mar 2023 19:27:56 +0000 (20:27 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sun, 19 Mar 2023 19:27:56 +0000 (20:27 +0100)
src/parser.cpp

index 59c22ab..28104e7 100644 (file)
@@ -115,7 +115,11 @@ namespace {
         std::stringstream ss(value);
         target = 0;
         while (!ss.eof() && ss >> file && ss >> rank)
+        {
+            if (Rank(rank - 1) > RANK_MAX || (file != '*' && File(tolower(file) - 'a') > FILE_MAX))
+                return false;
             target |= file == '*' ? rank_bb(Rank(rank - 1)) : square_bb(make_square(File(tolower(file) - 'a'), Rank(rank - 1)));
+        }
         return !ss.fail();
     }