Save large connection IDs on the heap

The IETF will soon increase the maximum size of connection IDs, this change allows us to scale that by placing large ones on the heap.

gfe-relnote: change representation of connection IDs, protected by quic_use_allocated_connection_ids
PiperOrigin-RevId: 252524833
Change-Id: Ia98aee46adebbe6f5f3df2a4c0062a54a22e2d0d
diff --git a/quic/core/quic_data_reader.cc b/quic/core/quic_data_reader.cc
index ef09483..951a144 100644
--- a/quic/core/quic_data_reader.cc
+++ b/quic/core/quic_data_reader.cc
@@ -146,10 +146,21 @@
     return true;
   }
 
-  const bool ok = ReadBytes(connection_id->mutable_data(), length);
-  if (ok) {
-    connection_id->set_length(length);
+  if (!GetQuicRestartFlag(quic_use_allocated_connection_ids)) {
+    const bool ok = ReadBytes(connection_id->mutable_data(), length);
+    if (ok) {
+      connection_id->set_length(length);
+    }
+    return ok;
   }
+
+  if (BytesRemaining() < length) {
+    return false;
+  }
+
+  connection_id->set_length(length);
+  const bool ok = ReadBytes(connection_id->mutable_data(), length);
+  DCHECK(ok);
   return ok;
 }