[idl_parser, JSON] Disable parsing of JSON for incomplete schemes (#6493)
authorVladimir Glavnyy <31897320+vglavnyy@users.noreply.github.com>
Mon, 1 Mar 2021 21:40:58 +0000 (04:40 +0700)
committerGitHub <noreply@github.com>
Mon, 1 Mar 2021 21:40:58 +0000 (13:40 -0800)
This commit disable JSON parsing for an incomplete scheme if JSON object is embedded into one file with the scheme.
This should improve the quality of OSS-Fuzz inputs for the parser_fuzzer target.

src/idl_parser.cpp

index 8cfd04bdcb451c57b413b53606c1e8789470924b..87b999d70b41d42e1fddbfbba909dc3641f868cf 100644 (file)
@@ -3189,6 +3189,9 @@ CheckedError Parser::ParseRoot(const char *source, const char **include_paths,
       }
     }
   }
+  // Parse JSON object only if the scheme has been parsed.
+  if (token_ == '{') { ECHECK(DoParseJson()); }
+  EXPECT(kTokenEof);
   return NoError();
 }
 
@@ -3308,7 +3311,7 @@ CheckedError Parser::DoParse(const char *source, const char **include_paths,
     } else if (IsIdent("namespace")) {
       ECHECK(ParseNamespace());
     } else if (token_ == '{') {
-      ECHECK(DoParseJson());
+      return NoError();
     } else if (IsIdent("enum")) {
       ECHECK(ParseEnum(false, nullptr));
     } else if (IsIdent("union")) {