MCPcopy Create free account
hub / github.com/apache/fory / CheckRemoteTypeMetaLimits

Method CheckRemoteTypeMetaLimits

csharp/src/Fory/ReadContext.cs:166–207  ·  view source on GitHub ↗
(TypeMeta typeMeta)

Source from the content-addressed store, hash-verified

164 }
165
166 [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
167 private object CheckRemoteTypeMetaLimits(TypeMeta typeMeta)
168 {
169 object typeKey;
170 if (typeMeta.RegisterByName)
171 {
172 typeKey = $"{typeMeta.NamespaceName.Value}\0{typeMeta.TypeName.Value}";
173 }
174 else if (typeMeta.UserTypeId.HasValue)
175 {
176 typeKey = typeMeta.UserTypeId.Value;
177 }
178 else
179 {
180 throw new InvalidDataException("remote metadata is missing type identity");
181 }
182 _remoteSchemaVersionsByType.TryGetValue(typeKey, out int versionsForType);
183 int maxSchemaVersionsPerType = _config.MaxSchemaVersionsPerType;
184 if (versionsForType >= maxSchemaVersionsPerType)
185 {
186 throw new InvalidDataException(
187 $"Remote schema version limit exceeded for type {typeKey}: {versionsForType} >= {maxSchemaVersionsPerType}. " +
188 "The data may be malicious. If the data is not malicious, please increase MaxSchemaVersionsPerType.");
189 }
190
191 int acceptedTypeCount = versionsForType == 0
192 ? _remoteSchemaVersionsByType.Count + 1
193 : _remoteSchemaVersionsByType.Count;
194 int maxAverageSchemaVersionsPerType = _config.MaxAverageSchemaVersionsPerType;
195 long globalLimit = Math.Max(
196 MinRemoteTypeMetaLimit,
197 (long)acceptedTypeCount * maxAverageSchemaVersionsPerType);
198 if (_totalAcceptedSchemaVersions >= globalLimit)
199 {
200 throw new InvalidDataException(
201 $"Remote schema version limit exceeded: {_totalAcceptedSchemaVersions} metadata versions for " +
202 $"{acceptedTypeCount} accepted remote types exceeds the average limit {maxAverageSchemaVersionsPerType}. " +
203 "The data may be malicious. If the data is not malicious, please increase MaxAverageSchemaVersionsPerType.");
204 }
205
206 return typeKey;
207 }
208
209 private void RecordRemoteTypeMetaVersion(object typeKey)
210 {

Callers

nothing calls this directly

Calls 1

TryGetValueMethod · 0.45

Tested by

no test coverage detected