diff --git a/.chloggen/pprofile-off-by-one.yaml b/.chloggen/pprofile-off-by-one.yaml new file mode 100644 index 00000000000..50b69564ace --- /dev/null +++ b/.chloggen/pprofile-off-by-one.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: 'bug_fix' + +# The name of the component, or a single word describing the area of concern, (e.g. receiver/otlp) +component: pdata/pprofile + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix off-by-one issue in dictionary lookups. + +# One or more tracking issues or pull requests related to the change +issues: [14534] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] diff --git a/pdata/pprofile/function.go b/pdata/pprofile/function.go index 021cb68a167..10bb1af9126 100644 --- a/pdata/pprofile/function.go +++ b/pdata/pprofile/function.go @@ -17,7 +17,7 @@ func (fn Function) Equal(val Function) bool { // dictionary to another. func (fn Function) switchDictionary(src, dst ProfilesDictionary) error { if fn.NameStrindex() > 0 { - if src.StringTable().Len() < int(fn.NameStrindex()) { + if src.StringTable().Len() <= int(fn.NameStrindex()) { return fmt.Errorf("invalid name index %d", fn.NameStrindex()) } @@ -29,7 +29,7 @@ func (fn Function) switchDictionary(src, dst ProfilesDictionary) error { } if fn.SystemNameStrindex() > 0 { - if src.StringTable().Len() < int(fn.SystemNameStrindex()) { + if src.StringTable().Len() <= int(fn.SystemNameStrindex()) { return fmt.Errorf("invalid system name index %d", fn.SystemNameStrindex()) } @@ -41,7 +41,7 @@ func (fn Function) switchDictionary(src, dst ProfilesDictionary) error { } if fn.FilenameStrindex() > 0 { - if src.StringTable().Len() < int(fn.FilenameStrindex()) { + if src.StringTable().Len() <= int(fn.FilenameStrindex()) { return fmt.Errorf("invalid filename index %d", fn.FilenameStrindex()) } diff --git a/pdata/pprofile/function_test.go b/pdata/pprofile/function_test.go index f5ef9b6259f..ff7c7cf7c45 100644 --- a/pdata/pprofile/function_test.go +++ b/pdata/pprofile/function_test.go @@ -138,6 +138,29 @@ func TestFunctionSwitchDictionary(t *testing.T) { wantDictionary: NewProfilesDictionary(), wantErr: errors.New("invalid name index 1"), }, + { + name: "with a name index equal to the source table length (boundary condition)", + function: func() Function { + fn := NewFunction() + fn.SetNameStrindex(2) // Index 2 with length 2 (indices 0,1 are valid) + return fn + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.StringTable().Append("", "test") // Length 2: indices 0,1 valid + return d + }(), + dst: NewProfilesDictionary(), + + wantFunction: func() Function { + fn := NewFunction() + fn.SetNameStrindex(2) + return fn + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid name index 2"), + }, { name: "with an existing system name", function: func() Function { @@ -187,6 +210,29 @@ func TestFunctionSwitchDictionary(t *testing.T) { wantDictionary: NewProfilesDictionary(), wantErr: errors.New("invalid system name index 1"), }, + { + name: "with a system name index equal to the source table length (boundary condition)", + function: func() Function { + fn := NewFunction() + fn.SetSystemNameStrindex(2) + return fn + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.StringTable().Append("", "test") + return d + }(), + dst: NewProfilesDictionary(), + + wantFunction: func() Function { + fn := NewFunction() + fn.SetSystemNameStrindex(2) + return fn + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid system name index 2"), + }, { name: "with an existing filename", function: func() Function { @@ -236,6 +282,29 @@ func TestFunctionSwitchDictionary(t *testing.T) { wantDictionary: NewProfilesDictionary(), wantErr: errors.New("invalid filename index 1"), }, + { + name: "with a filename index equal to the source table length (boundary condition)", + function: func() Function { + fn := NewFunction() + fn.SetFilenameStrindex(2) + return fn + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.StringTable().Append("", "test") + return d + }(), + dst: NewProfilesDictionary(), + + wantFunction: func() Function { + fn := NewFunction() + fn.SetFilenameStrindex(2) + return fn + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid filename index 2"), + }, } { t.Run(tt.name, func(t *testing.T) { fn := tt.function diff --git a/pdata/pprofile/keyvalueandunit.go b/pdata/pprofile/keyvalueandunit.go index 4ec70d911d7..47bf4d151db 100644 --- a/pdata/pprofile/keyvalueandunit.go +++ b/pdata/pprofile/keyvalueandunit.go @@ -17,7 +17,7 @@ func (ms KeyValueAndUnit) Equal(val KeyValueAndUnit) bool { // dictionary to another. func (ms KeyValueAndUnit) switchDictionary(src, dst ProfilesDictionary) error { if ms.KeyStrindex() > 0 { - if src.StringTable().Len() < int(ms.KeyStrindex()) { + if src.StringTable().Len() <= int(ms.KeyStrindex()) { return fmt.Errorf("invalid key index %d", ms.KeyStrindex()) } @@ -29,7 +29,7 @@ func (ms KeyValueAndUnit) switchDictionary(src, dst ProfilesDictionary) error { } if ms.UnitStrindex() > 0 { - if src.StringTable().Len() < int(ms.UnitStrindex()) { + if src.StringTable().Len() <= int(ms.UnitStrindex()) { return fmt.Errorf("invalid unit index %d", ms.UnitStrindex()) } diff --git a/pdata/pprofile/keyvalueandunit_test.go b/pdata/pprofile/keyvalueandunit_test.go index bfbb3b7c4d6..db75ec6d574 100644 --- a/pdata/pprofile/keyvalueandunit_test.go +++ b/pdata/pprofile/keyvalueandunit_test.go @@ -133,6 +133,29 @@ func TestKeyValueAndUnitSwitchDictionary(t *testing.T) { wantDictionary: NewProfilesDictionary(), wantErr: errors.New("invalid key index 1"), }, + { + name: "with a key index equal to the source table length (boundary condition)", + keyValueAndUnit: func() KeyValueAndUnit { + kvu := NewKeyValueAndUnit() + kvu.SetKeyStrindex(2) + return kvu + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.StringTable().Append("", "test") + return d + }(), + dst: NewProfilesDictionary(), + + wantKeyValueAndUnit: func() KeyValueAndUnit { + kvu := NewKeyValueAndUnit() + kvu.SetKeyStrindex(2) + return kvu + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid key index 2"), + }, { name: "with an existing unit", keyValueAndUnit: func() KeyValueAndUnit { @@ -182,6 +205,29 @@ func TestKeyValueAndUnitSwitchDictionary(t *testing.T) { wantDictionary: NewProfilesDictionary(), wantErr: errors.New("invalid unit index 1"), }, + { + name: "with a unit index equal to the source table length (boundary condition)", + keyValueAndUnit: func() KeyValueAndUnit { + kvu := NewKeyValueAndUnit() + kvu.SetUnitStrindex(2) + return kvu + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.StringTable().Append("", "test") + return d + }(), + dst: NewProfilesDictionary(), + + wantKeyValueAndUnit: func() KeyValueAndUnit { + kvu := NewKeyValueAndUnit() + kvu.SetUnitStrindex(2) + return kvu + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid unit index 2"), + }, } { t.Run(tt.name, func(t *testing.T) { kvu := tt.keyValueAndUnit diff --git a/pdata/pprofile/line.go b/pdata/pprofile/line.go index 57ba32bcfe6..7ed3461dddc 100644 --- a/pdata/pprofile/line.go +++ b/pdata/pprofile/line.go @@ -31,7 +31,7 @@ func (l Line) Equal(val Line) bool { // dictionary to another. func (l Line) switchDictionary(src, dst ProfilesDictionary) error { if l.FunctionIndex() > 0 { - if src.FunctionTable().Len() < int(l.FunctionIndex()) { + if src.FunctionTable().Len() <= int(l.FunctionIndex()) { return fmt.Errorf("invalid function index %d", l.FunctionIndex()) } diff --git a/pdata/pprofile/line_test.go b/pdata/pprofile/line_test.go index 0d87d0b3bda..6bdab7336ff 100644 --- a/pdata/pprofile/line_test.go +++ b/pdata/pprofile/line_test.go @@ -206,6 +206,30 @@ func TestLineSwitchDictionary(t *testing.T) { wantDictionary: NewProfilesDictionary(), wantErr: errors.New("invalid function index 1"), }, + { + name: "with a function index equal to the source table length (boundary condition)", + line: func() Line { + l := NewLine() + l.SetFunctionIndex(2) + return l + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.FunctionTable().AppendEmpty() + d.FunctionTable().AppendEmpty() // Length 2: indices 0,1 valid + return d + }(), + dst: NewProfilesDictionary(), + + wantLine: func() Line { + l := NewLine() + l.SetFunctionIndex(2) + return l + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid function index 2"), + }, } { t.Run(tt.name, func(t *testing.T) { line := tt.line diff --git a/pdata/pprofile/location.go b/pdata/pprofile/location.go index e63f52ce709..a6963b3c9dc 100644 --- a/pdata/pprofile/location.go +++ b/pdata/pprofile/location.go @@ -17,7 +17,7 @@ func (ms Location) Equal(val Location) bool { // dictionary to another. func (ms Location) switchDictionary(src, dst ProfilesDictionary) error { if ms.MappingIndex() > 0 { - if src.MappingTable().Len() < int(ms.MappingIndex()) { + if src.MappingTable().Len() <= int(ms.MappingIndex()) { return fmt.Errorf("invalid mapping index %d", ms.MappingIndex()) } @@ -34,7 +34,7 @@ func (ms Location) switchDictionary(src, dst ProfilesDictionary) error { } for i, v := range ms.AttributeIndices().All() { - if src.AttributeTable().Len() < int(v) { + if src.AttributeTable().Len() <= int(v) { return fmt.Errorf("invalid attribute index %d", v) } diff --git a/pdata/pprofile/location_test.go b/pdata/pprofile/location_test.go index b489b258537..f9c40147043 100644 --- a/pdata/pprofile/location_test.go +++ b/pdata/pprofile/location_test.go @@ -150,6 +150,30 @@ func TestLocationSwitchDictionary(t *testing.T) { wantDictionary: NewProfilesDictionary(), wantErr: errors.New("invalid mapping index 1"), }, + { + name: "with a mapping index equal to the source table length (boundary condition)", + location: func() Location { + l := NewLocation() + l.SetMappingIndex(2) + return l + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.MappingTable().AppendEmpty() + d.MappingTable().AppendEmpty() + return d + }(), + dst: NewProfilesDictionary(), + + wantLocation: func() Location { + l := NewLocation() + l.SetMappingIndex(2) + return l + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid mapping index 2"), + }, { name: "with an existing attribute", location: func() Location { @@ -212,6 +236,30 @@ func TestLocationSwitchDictionary(t *testing.T) { wantDictionary: NewProfilesDictionary(), wantErr: errors.New("invalid attribute index 1"), }, + { + name: "with an attribute index equal to the source table length (boundary condition)", + location: func() Location { + l := NewLocation() + l.AttributeIndices().Append(2) + return l + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.AttributeTable().AppendEmpty() + d.AttributeTable().AppendEmpty() + return d + }(), + dst: NewProfilesDictionary(), + + wantLocation: func() Location { + l := NewLocation() + l.AttributeIndices().Append(2) + return l + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid attribute index 2"), + }, { name: "with an existing line", location: func() Location { diff --git a/pdata/pprofile/mapping.go b/pdata/pprofile/mapping.go index 7989f3c14ab..2b857fb2344 100644 --- a/pdata/pprofile/mapping.go +++ b/pdata/pprofile/mapping.go @@ -18,7 +18,7 @@ func (ms Mapping) Equal(val Mapping) bool { // dictionary to another. func (ms Mapping) switchDictionary(src, dst ProfilesDictionary) error { if ms.FilenameStrindex() > 0 { - if src.StringTable().Len() < int(ms.FilenameStrindex()) { + if src.StringTable().Len() <= int(ms.FilenameStrindex()) { return fmt.Errorf("invalid filename index %d", ms.FilenameStrindex()) } @@ -30,7 +30,7 @@ func (ms Mapping) switchDictionary(src, dst ProfilesDictionary) error { } for i, v := range ms.AttributeIndices().All() { - if src.AttributeTable().Len() < int(v) { + if src.AttributeTable().Len() <= int(v) { return fmt.Errorf("invalid attribute index %d", v) } diff --git a/pdata/pprofile/mapping_test.go b/pdata/pprofile/mapping_test.go index 8be426e6c0b..b4b12fcf3ff 100644 --- a/pdata/pprofile/mapping_test.go +++ b/pdata/pprofile/mapping_test.go @@ -144,6 +144,29 @@ func TestMappingSwitchDictionary(t *testing.T) { wantDictionary: NewProfilesDictionary(), wantErr: errors.New("invalid filename index 1"), }, + { + name: "with a filename index equal to the source table length (boundary condition)", + mapping: func() Mapping { + m := NewMapping() + m.SetFilenameStrindex(2) + return m + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.StringTable().Append("", "test") + return d + }(), + dst: NewProfilesDictionary(), + + wantMapping: func() Mapping { + m := NewMapping() + m.SetFilenameStrindex(2) + return m + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid filename index 2"), + }, { name: "with an existing attribute", mapping: func() Mapping { @@ -206,6 +229,30 @@ func TestMappingSwitchDictionary(t *testing.T) { wantDictionary: NewProfilesDictionary(), wantErr: errors.New("invalid attribute index 1"), }, + { + name: "with an attribute index equal to the source table length (boundary condition)", + mapping: func() Mapping { + m := NewMapping() + m.AttributeIndices().Append(2) + return m + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.AttributeTable().AppendEmpty() + d.AttributeTable().AppendEmpty() + return d + }(), + dst: NewProfilesDictionary(), + + wantMapping: func() Mapping { + m := NewMapping() + m.AttributeIndices().Append(2) + return m + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid attribute index 2"), + }, } { t.Run(tt.name, func(t *testing.T) { m := tt.mapping diff --git a/pdata/pprofile/profile.go b/pdata/pprofile/profile.go index 34690c6f93a..dd92ee3092f 100644 --- a/pdata/pprofile/profile.go +++ b/pdata/pprofile/profile.go @@ -13,7 +13,7 @@ import ( // dictionary to another. func (ms Profile) switchDictionary(src, dst ProfilesDictionary) error { for i, v := range ms.AttributeIndices().All() { - if src.AttributeTable().Len() < int(v) { + if src.AttributeTable().Len() <= int(v) { return fmt.Errorf("invalid attribute index %d", v) } diff --git a/pdata/pprofile/profile_test.go b/pdata/pprofile/profile_test.go index ff8bedb3422..2373cf38a49 100644 --- a/pdata/pprofile/profile_test.go +++ b/pdata/pprofile/profile_test.go @@ -98,6 +98,30 @@ func TestProfileSwitchDictionary(t *testing.T) { wantDictionary: NewProfilesDictionary(), wantErr: errors.New("invalid attribute index 1"), }, + { + name: "with an attribute index equal to the source table length (boundary condition)", + profile: func() Profile { + p := NewProfile() + p.AttributeIndices().Append(2) + return p + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.AttributeTable().AppendEmpty() + d.AttributeTable().AppendEmpty() + return d + }(), + dst: NewProfilesDictionary(), + + wantProfile: func() Profile { + p := NewProfile() + p.AttributeIndices().Append(2) + return p + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid attribute index 2"), + }, { name: "with a profile that has a sample", profile: func() Profile { diff --git a/pdata/pprofile/sample.go b/pdata/pprofile/sample.go index a0bbd29ffea..23db19e9c32 100644 --- a/pdata/pprofile/sample.go +++ b/pdata/pprofile/sample.go @@ -9,7 +9,7 @@ import "fmt" // dictionary to another. func (ms Sample) switchDictionary(src, dst ProfilesDictionary) error { for i, v := range ms.AttributeIndices().All() { - if src.AttributeTable().Len() < int(v) { + if src.AttributeTable().Len() <= int(v) { return fmt.Errorf("invalid attribute index %d", v) } @@ -26,7 +26,7 @@ func (ms Sample) switchDictionary(src, dst ProfilesDictionary) error { } if ms.LinkIndex() > 0 { - if src.LinkTable().Len() < int(ms.LinkIndex()) { + if src.LinkTable().Len() <= int(ms.LinkIndex()) { return fmt.Errorf("invalid link index %d", ms.LinkIndex()) } @@ -38,7 +38,7 @@ func (ms Sample) switchDictionary(src, dst ProfilesDictionary) error { } if ms.StackIndex() > 0 { - if src.StackTable().Len() < int(ms.StackIndex()) { + if src.StackTable().Len() <= int(ms.StackIndex()) { return fmt.Errorf("invalid stack index %d", ms.StackIndex()) } diff --git a/pdata/pprofile/sample_test.go b/pdata/pprofile/sample_test.go index 4efe651d547..313cd8a3c7d 100644 --- a/pdata/pprofile/sample_test.go +++ b/pdata/pprofile/sample_test.go @@ -98,6 +98,30 @@ func TestSampleSwitchDictionary(t *testing.T) { wantDictionary: NewProfilesDictionary(), wantErr: errors.New("invalid attribute index 1"), }, + { + name: "with an attribute index equal to the source table length (boundary condition)", + sample: func() Sample { + s := NewSample() + s.AttributeIndices().Append(2) + return s + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.AttributeTable().AppendEmpty() + d.AttributeTable().AppendEmpty() + return d + }(), + dst: NewProfilesDictionary(), + + wantSample: func() Sample { + s := NewSample() + s.AttributeIndices().Append(2) + return s + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid attribute index 2"), + }, { name: "with an existing link", sample: func() Sample { @@ -153,6 +177,30 @@ func TestSampleSwitchDictionary(t *testing.T) { wantDictionary: NewProfilesDictionary(), wantErr: errors.New("invalid link index 1"), }, + { + name: "with a link index equal to the source table length (boundary condition)", + sample: func() Sample { + s := NewSample() + s.SetLinkIndex(2) + return s + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.LinkTable().AppendEmpty() + d.LinkTable().AppendEmpty() + return d + }(), + dst: NewProfilesDictionary(), + + wantSample: func() Sample { + s := NewSample() + s.SetLinkIndex(2) + return s + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid link index 2"), + }, { name: "with an existing stack", sample: func() Sample { @@ -213,6 +261,30 @@ func TestSampleSwitchDictionary(t *testing.T) { wantDictionary: NewProfilesDictionary(), wantErr: errors.New("invalid stack index 1"), }, + { + name: "with a stack index equal to the source table length (boundary condition)", + sample: func() Sample { + s := NewSample() + s.SetStackIndex(2) + return s + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.StackTable().AppendEmpty() + d.StackTable().AppendEmpty() + return d + }(), + dst: NewProfilesDictionary(), + + wantSample: func() Sample { + s := NewSample() + s.SetStackIndex(2) + return s + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid stack index 2"), + }, } { t.Run(tt.name, func(t *testing.T) { sample := tt.sample diff --git a/pdata/pprofile/stack.go b/pdata/pprofile/stack.go index 87fd216ef3e..8d4f5be1d97 100644 --- a/pdata/pprofile/stack.go +++ b/pdata/pprofile/stack.go @@ -26,7 +26,7 @@ func (ms Stack) Equal(val Stack) bool { // dictionary to another. func (ms Stack) switchDictionary(src, dst ProfilesDictionary) error { for i, v := range ms.LocationIndices().All() { - if src.LocationTable().Len() < int(v) { + if src.LocationTable().Len() <= int(v) { return fmt.Errorf("invalid location index %d", v) } diff --git a/pdata/pprofile/stack_test.go b/pdata/pprofile/stack_test.go index 00cc33e65ce..51fa9152f3e 100644 --- a/pdata/pprofile/stack_test.go +++ b/pdata/pprofile/stack_test.go @@ -178,6 +178,31 @@ func TestStackSwitchDictionary(t *testing.T) { }(), wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid location index 2"), + }, + { + name: "with a location index equal to the source table length (boundary condition)", + stack: func() Stack { + s := NewStack() + s.LocationIndices().Append(2) // Index 2 with length 2 (indices 0,1 are valid) + return s + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.LocationTable().AppendEmpty() // Index 0 + d.LocationTable().AppendEmpty() // Index 1 + return d + }(), + dst: NewProfilesDictionary(), + + wantStack: func() Stack { + s := NewStack() + s.LocationIndices().Append(2) + return s + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid location index 2"), }, } { diff --git a/pdata/pprofile/valuetype.go b/pdata/pprofile/valuetype.go index 2d2e735c018..1d6339f68cf 100644 --- a/pdata/pprofile/valuetype.go +++ b/pdata/pprofile/valuetype.go @@ -9,7 +9,7 @@ import "fmt" // dictionary to another. func (ms ValueType) switchDictionary(src, dst ProfilesDictionary) error { if ms.TypeStrindex() > 0 { - if src.StringTable().Len() < int(ms.TypeStrindex()) { + if src.StringTable().Len() <= int(ms.TypeStrindex()) { return fmt.Errorf("invalid type index %d", ms.TypeStrindex()) } @@ -21,7 +21,7 @@ func (ms ValueType) switchDictionary(src, dst ProfilesDictionary) error { } if ms.UnitStrindex() > 0 { - if src.StringTable().Len() < int(ms.UnitStrindex()) { + if src.StringTable().Len() <= int(ms.UnitStrindex()) { return fmt.Errorf("invalid unit index %d", ms.UnitStrindex()) } diff --git a/pdata/pprofile/valuetype_test.go b/pdata/pprofile/valuetype_test.go index 19539c5ab02..999721a443e 100644 --- a/pdata/pprofile/valuetype_test.go +++ b/pdata/pprofile/valuetype_test.go @@ -84,6 +84,29 @@ func TestValueTypeSwitchDictionary(t *testing.T) { wantDictionary: NewProfilesDictionary(), wantErr: errors.New("invalid type index 1"), }, + { + name: "with a type index equal to the source table length (boundary condition)", + valueType: func() ValueType { + vt := NewValueType() + vt.SetTypeStrindex(2) + return vt + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.StringTable().Append("", "test") + return d + }(), + dst: NewProfilesDictionary(), + + wantValueType: func() ValueType { + vt := NewValueType() + vt.SetTypeStrindex(2) + return vt + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid type index 2"), + }, { name: "with an existing unit", valueType: func() ValueType { @@ -133,6 +156,29 @@ func TestValueTypeSwitchDictionary(t *testing.T) { wantDictionary: NewProfilesDictionary(), wantErr: errors.New("invalid unit index 1"), }, + { + name: "with a unit index equal to the source table length (boundary condition)", + valueType: func() ValueType { + vt := NewValueType() + vt.SetUnitStrindex(2) + return vt + }(), + + src: func() ProfilesDictionary { + d := NewProfilesDictionary() + d.StringTable().Append("", "test") + return d + }(), + dst: NewProfilesDictionary(), + + wantValueType: func() ValueType { + vt := NewValueType() + vt.SetUnitStrindex(2) + return vt + }(), + wantDictionary: NewProfilesDictionary(), + wantErr: errors.New("invalid unit index 2"), + }, } { t.Run(tt.name, func(t *testing.T) { vt := tt.valueType