2edf28
--- a/src/google/protobuf/descriptor.cc.orig	2017-11-13 19:47:29.000000000 +0100
2edf28
+++ b/src/google/protobuf/descriptor.cc	2022-03-08 17:00:19.057041566 +0100
2edf28
@@ -2591,6 +2591,8 @@
2edf28
       const Descriptor::ReservedRange* range = reserved_range(i);
2edf28
       if (range->end == range->start + 1) {
2edf28
         strings::SubstituteAndAppend(contents, "$0, ", range->start);
2edf28
+      } else if (range->end > FieldDescriptor::kMaxNumber) {
2edf28
+        strings::SubstituteAndAppend(contents, "$0 to max, ", range->start);
2edf28
       } else {
2edf28
         strings::SubstituteAndAppend(contents, "$0 to $1, ",
2edf28
                                      range->start, range->end - 1);
2edf28
@@ -2810,6 +2812,8 @@
2edf28
       const EnumDescriptor::ReservedRange* range = reserved_range(i);
2edf28
       if (range->end == range->start) {
2edf28
         strings::SubstituteAndAppend(contents, "$0, ", range->start);
2edf28
+      } else if (range->end == INT_MAX) {
2edf28
+        strings::SubstituteAndAppend(contents, "$0 to max, ", range->start);
2edf28
       } else {
2edf28
         strings::SubstituteAndAppend(contents, "$0 to $1, ",
2edf28
                                      range->start, range->end);
2edf28
@@ -3983,6 +3987,11 @@
2edf28
   // Use its file as the parent instead.
2edf28
   if (parent == NULL) parent = file_;
2edf28
 
2edf28
+  if (full_name.find('\0') != std::string::npos) {
2edf28
+    AddError(full_name, proto, DescriptorPool::ErrorCollector::NAME,
2edf28
+             "\"" + full_name + "\" contains null character.");
2edf28
+    return false;
2edf28
+  }
2edf28
   if (tables_->AddSymbol(full_name, symbol)) {
2edf28
     if (!file_tables_->AddAliasUnderParent(parent, name, symbol)) {
2edf28
       // This is only possible if there was already an error adding something of
2edf28
@@ -4020,6 +4029,11 @@
2edf28
 
2edf28
 void DescriptorBuilder::AddPackage(
2edf28
     const string& name, const Message& proto, const FileDescriptor* file) {
2edf28
+  if (name.find('\0') != std::string::npos) {
2edf28
+    AddError(name, proto, DescriptorPool::ErrorCollector::NAME,
2edf28
+             "\"" + name + "\" contains null character.");
2edf28
+    return;
2edf28
+  }
2edf28
   if (tables_->AddSymbol(name, Symbol(file))) {
2edf28
     // Success.  Also add parent package, if any.
2edf28
     string::size_type dot_pos = name.find_last_of('.');
2edf28
@@ -4288,6 +4302,12 @@
2edf28
   }
2edf28
   result->pool_ = pool_;
2edf28
 
2edf28
+  if (result->name().find('\0') != std::string::npos) {
2edf28
+    AddError(result->name(), proto, DescriptorPool::ErrorCollector::NAME,
2edf28
+             "\"" + result->name() + "\" contains null character.");
2edf28
+    return nullptr;
2edf28
+  }
2edf28
+
2edf28
   // Add to tables.
2edf28
   if (!tables_->AddFile(result)) {
2edf28
     AddError(proto.name(), proto, DescriptorPool::ErrorCollector::OTHER,