Copilot commented on code in PR #3889:
URL: https://github.com/apache/avro/pull/3889#discussion_r3612637314


##########
lang/c++/impl/Compiler.cc:
##########
@@ -132,6 +133,21 @@ string getStringField(const Entity &e, const Object &m,
     return it->second.stringValue();
 }
 
+// Validates that a record field name or enum symbol conforms to the Avro name
+// grammar (a non-empty sequence of [A-Za-z0-9_], as already enforced for named
+// type simple names by Name::check()). This prevents out-of-spec strings from
+// being emitted verbatim as identifiers by the C++ code generator.
+static void validateSimpleName(const string &name, const char *what) {
+    if (name.empty()) {
+        throw Exception("Empty {} name", what);
+    }
+    for (const char c : name) {
+        if (!std::isalnum(static_cast<unsigned char>(c)) && c != '_') {
+            throw Exception("Invalid {} name: {}", what, name);
+        }
+    }
+}

Review Comment:
   validateSimpleName() uses std::isalnum, which is locale-dependent and can 
accept characters outside the intended ASCII Avro name grammar described in the 
comment ([A-Za-z0-9_]). That can allow out-of-spec field/symbol names to slip 
through on non-"C" locales.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to