Skip to content

Commit b9fca8b

Browse files
committed
bounds-protect type evaluation depth
Signed-off-by: grokspawn <jordan@nimblewidget.com>
1 parent e048b50 commit b9fca8b

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

internal/catalogd/graphql/graphql.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ func determineFieldType(value interface{}) (reflect.Kind, bool) {
335335
}
336336

337337
const maxSampleElements = 10
338+
const maxSampleValues = 10
338339

339340
// analyzeFieldValue analyzes a field value and returns type info, sample value, and nested fields.
340341
// For slices, it examines up to maxSampleElements to detect heterogeneous element types
@@ -439,6 +440,9 @@ func mergeNestedFields(existing, new map[string]*FieldInfo) {
439440
if existingInfo, ok := existing[fieldName]; ok {
440441
// Merge sample values
441442
for _, sample := range newInfo.SampleValues {
443+
if len(existingInfo.SampleValues) >= maxSampleValues {
444+
break
445+
}
442446
existingInfo.SampleValues = appendUnique(existingInfo.SampleValues, sample)
443447
}
444448
} else {
@@ -481,7 +485,9 @@ func analyzeJSONObject(obj map[string]interface{}, info *SchemaInfo) {
481485
}
482486

483487
// Update existing field
484-
existing.SampleValues = appendUnique(existing.SampleValues, sampleValue)
488+
if len(existing.SampleValues) < maxSampleValues {
489+
existing.SampleValues = appendUnique(existing.SampleValues, sampleValue)
490+
}
485491

486492
// Merge nested fields if discovered
487493
if nestedFields == nil {

0 commit comments

Comments
 (0)