[llvm-branch-commits] [llvm] [Remarks] Escape control characters in YAML remark arguments and decode them when parsing (PR #227654)

Henrich Lauko via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Oct 1 06:22:57 PDT 2026


================
@@ -265,22 +265,21 @@ Expected<StringRef> YAMLRemarkParser::parseKey(yaml::KeyValueNode &Node) {
 }
 
 Expected<StringRef> YAMLRemarkParser::parseStr(yaml::KeyValueNode &Node) {
-  auto *Value = dyn_cast_if_present<yaml::ScalarNode>(Node.getValue());
-  yaml::BlockScalarNode *ValueBlock;
-  StringRef Result;
-  if (!Value) {
-    // Try to parse the value as a block node.
-    ValueBlock = dyn_cast_if_present<yaml::BlockScalarNode>(Node.getValue());
-    if (!ValueBlock)
-      return error("expected a value of scalar type.", Node);
-    Result = ValueBlock->getValue();
-  } else
-    Result = Value->getRawValue();
-
-  Result.consume_front("\'");
-  Result.consume_back("\'");
-
-  return Result;
+  yaml::Node *Value = Node.getValue();
+  // A block value lives in the YAML document, which next() frees before
+  // returning the remark.
+  if (auto *Block = dyn_cast_if_present<yaml::BlockScalarNode>(Value))
+    return Block->getValue().copy(Alloc);
+
+  auto *Scalar = dyn_cast_if_present<yaml::ScalarNode>(Value);
+  if (!Scalar)
+    return error("expected a value of scalar type.", Node);
+  SmallString<32> Storage;
+  StringRef Result = Scalar->getValue(Storage);
----------------
xlauko wrote:

Worse than a cut-off. The bitstream string table splits on NUL, so every later string gets the wrong index.
I changed YAML parser to reject NUL, and added a test for it.

https://github.com/llvm/llvm-project/pull/227654


More information about the llvm-branch-commits mailing list