]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
grammar-parser : fix possible null-deref (#9004)
authorDavidKorczynski <redacted>
Mon, 12 Aug 2024 12:36:41 +0000 (13:36 +0100)
committerGitHub <redacted>
Mon, 12 Aug 2024 12:36:41 +0000 (15:36 +0300)
Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=70680
Signed-off-by: David Korczynski <redacted>
common/grammar-parser.cpp

index a518b766dc33e5a3bf5921cacbe62184363fffab..438452eab570f430b0e40a49916da6148b0f88f6 100644 (file)
@@ -369,6 +369,9 @@ namespace grammar_parser {
             }
             // Validate the state to ensure that all rules are defined
             for (const auto & rule : state.rules) {
+                if (rule.empty()) {
+                    throw std::runtime_error("Undefined rule");
+                }
                 for (const auto & elem : rule) {
                     if (elem.type == LLAMA_GRETYPE_RULE_REF) {
                         // Ensure that the rule at that location exists