Skip to content

Commit a0a8a9e

Browse files
committed
[chore] rely on strict input parsing to error out on invalid unsigned int values
1 parent 6fcebdb commit a0a8a9e

File tree

2 files changed

+1
-15
lines changed

2 files changed

+1
-15
lines changed

confmap/confmap.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ func decodeConfig(m *Conf, result any, errorUnused bool, skipTopLevelUnmarshaler
170170
// we unmarshal the embedded structs if present to merge with the result:
171171
unmarshalerEmbeddedStructsHookFunc(),
172172
zeroSliceHookFunc(),
173-
negativeUintHookFunc(),
174173
),
175174
}
176175
decoder, err := mapstructure.NewDecoder(dc)
@@ -438,19 +437,6 @@ func zeroSliceHookFunc() mapstructure.DecodeHookFuncValue {
438437
}
439438
}
440439

441-
// This hook is used to solve the issue: https://github.com/open-telemetry/opentelemetry-collector/issues/9060
442-
// Decoding should fail when converting a negative integer to any type of unsigned integer. This prevents
443-
// negative values being decoded as large uint values.
444-
// TODO: This should be removed as a part of https://github.com/open-telemetry/opentelemetry-collector/issues/9532
445-
func negativeUintHookFunc() mapstructure.DecodeHookFuncValue {
446-
return func(from reflect.Value, to reflect.Value) (interface{}, error) {
447-
if from.CanInt() && from.Int() < 0 && to.CanUint() {
448-
return nil, fmt.Errorf("cannot convert negative value %v to an unsigned integer", from.Int())
449-
}
450-
return from.Interface(), nil
451-
}
452-
}
453-
454440
type moduleFactory[T any, S any] interface {
455441
Create(s S) T
456442
}

confmap/confmap_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func TestUintUnmarshalerFailure(t *testing.T) {
279279
err := conf.Unmarshal(cfg)
280280

281281
assert.Error(t, err)
282-
assert.Contains(t, err.Error(), fmt.Sprintf("* error decoding 'uint_test': cannot convert negative value %v to an unsigned integer", testValue))
282+
assert.Contains(t, err.Error(), fmt.Sprintf("1 error(s) decoding:\n\n* cannot parse 'uint_test', %d overflows uint", testValue))
283283
}
284284

285285
func TestMapKeyStringToMapKeyTextUnmarshalerHookFuncDuplicateID(t *testing.T) {

0 commit comments

Comments
 (0)