Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/fwschemadata: Prevent panics in ValueSemanticEqualityListElements and ValueSemanticEqualitySetElements methods when the length of newValueElements is greater than priorValueElements #772

Merged
merged 4 commits into from
Jun 14, 2023

Conversation

SBGoods
Copy link
Contributor

@SBGoods SBGoods commented Jun 14, 2023

Prevents panics when using types.ListType and types.SetType attributes with a nested ElementType with semantic equality and the proposed new value elements is greater than the prior value elements.

Covering tests results before logic update:

--- FAIL: TestValueSemanticEqualityList (0.00s)
    --- FAIL: TestValueSemanticEqualityList/ListValue-ListValue-StringValuableWithSemanticEquals-NewValueElementsGreaterThanPriorValueElements (0.00s)
panic: runtime error: index out of range [1] with length 1 [recovered]
	panic: runtime error: index out of range [1] with length 1

goroutine 5 [running]:
testing.tRunner.func1.2({0x100c59dc0, 0x140000180d8})
	/opt/homebrew/Cellar/go/1.19.4/libexec/src/testing/testing.go:1396 +0x1c8
testing.tRunner.func1()
	/opt/homebrew/Cellar/go/1.19.4/libexec/src/testing/testing.go:1399 +0x378
panic({0x100c59dc0, 0x140000180d8})
	/opt/homebrew/Cellar/go/1.19.4/libexec/src/runtime/panic.go:884 +0x204
github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata.ValueSemanticEqualityListElements({0x100c7dd80, 0x14000065ec0}, {{{0x140001198a0, 0x2, 0x2}}, {0x100c7ee48, 0x14000064f30}, {0x100c7ee48, 0x14000064f60}}, 0x14000065e60)
	/Users/sgoods/Hashicorp/terraform-plugin-framework/internal/fwschemadata/value_semantic_equality_list.go:145 +0xa20
github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata.ValueSemanticEqualityList({0x100c7dd80, 0x14000065ec0}, {{{0x140001198a0, 0x2, 0x2}}, {0x100c7ee48, 0x14000064f30}, {0x100c7ee48, 0x14000064f60}}, 0x14000065e60)
	/Users/sgoods/Hashicorp/terraform-plugin-framework/internal/fwschemadata/value_semantic_equality_list.go:27 +0x314
github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata.ValueSemanticEquality({0x100c7dd10, 0x1400001c100}, {{{0x140001198a0, 0x2, 0x2}}, {0x100c7ee48, 0x14000064f30}, {0x100c7ee48, 0x14000064f60}}, 0x14000065e60)
	/Users/sgoods/Hashicorp/terraform-plugin-framework/internal/fwschemadata/value_semantic_equality.go:71 +0x254
github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata.ValueSemanticEqualityListElements({0x100c7dd10, 0x1400001c100}, {{{0x14000050c90, 0x1, 0x1}}, {0x100c7ee48, 0x14000064fc0}, {0x100c7ee48, 0x14000064ff0}}, 0x14000065e30)
	/Users/sgoods/Hashicorp/terraform-plugin-framework/internal/fwschemadata/value_semantic_equality_list.go:152 +0x5e4
github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata.ValueSemanticEqualityList({0x100c7dd10, 0x1400001c100}, {{{0x14000050c90, 0x1, 0x1}}, {0x100c7ee48, 0x14000064fc0}, {0x100c7ee48, 0x14000064ff0}}, 0x14000065e30)
	/Users/sgoods/Hashicorp/terraform-plugin-framework/internal/fwschemadata/value_semantic_equality_list.go:27 +0x314
github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata_test.TestValueSemanticEqualityList.func1(0x14000003a00)
	/Users/sgoods/Hashicorp/terraform-plugin-framework/internal/fwschemadata/value_semantic_equality_list_test.go:650 +0xa0
testing.tRunner(0x14000003a00, 0x14000010cd0)
	/opt/homebrew/Cellar/go/1.19.4/libexec/src/testing/testing.go:1446 +0x10c
created by testing.(*T).Run
	/opt/homebrew/Cellar/go/1.19.4/libexec/src/testing/testing.go:1493 +0x300


--- FAIL: TestValueSemanticEqualitySet (0.00s)
    --- FAIL: TestValueSemanticEqualitySet/SetValue-SetValue-StringValuableWithSemanticEquals-NewValueElementsGreaterThanPriorValueElements (0.00s)
panic: runtime error: index out of range [1] with length 1 [recovered]
	panic: runtime error: index out of range [1] with length 1

goroutine 5 [running]:
testing.tRunner.func1.2({0x105545dc0, 0x14000018108})
	/opt/homebrew/Cellar/go/1.19.4/libexec/src/testing/testing.go:1396 +0x1c8
testing.tRunner.func1()
	/opt/homebrew/Cellar/go/1.19.4/libexec/src/testing/testing.go:1399 +0x378
panic({0x105545dc0, 0x14000018108})
	/opt/homebrew/Cellar/go/1.19.4/libexec/src/runtime/panic.go:884 +0x204
github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata.ValueSemanticEqualitySetElements({0x105569d80, 0x14000065ec0}, {{{0x140001198a0, 0x2, 0x2}}, {0x10556b088, 0x14000064f30}, {0x10556b088, 0x14000064f60}}, 0x14000065e60)
	/Users/sgoods/Hashicorp/terraform-plugin-framework/internal/fwschemadata/value_semantic_equality_set.go:145 +0xa3c
github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata.ValueSemanticEqualitySet({0x105569d80, 0x14000065ec0}, {{{0x140001198a0, 0x2, 0x2}}, {0x10556b088, 0x14000064f30}, {0x10556b088, 0x14000064f60}}, 0x14000065e60)
	/Users/sgoods/Hashicorp/terraform-plugin-framework/internal/fwschemadata/value_semantic_equality_set.go:27 +0x314
github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata.ValueSemanticEquality({0x105569d10, 0x1400001c100}, {{{0x140001198a0, 0x2, 0x2}}, {0x10556b088, 0x14000064f30}, {0x10556b088, 0x14000064f60}}, 0x14000065e60)
	/Users/sgoods/Hashicorp/terraform-plugin-framework/internal/fwschemadata/value_semantic_equality.go:79 +0x374
github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata.ValueSemanticEqualitySetElements({0x105569d10, 0x1400001c100}, {{{0x14000050c90, 0x1, 0x1}}, {0x10556b088, 0x14000064fc0}, {0x10556b088, 0x14000064ff0}}, 0x14000065e30)
	/Users/sgoods/Hashicorp/terraform-plugin-framework/internal/fwschemadata/value_semantic_equality_set.go:152 +0x600
github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata.ValueSemanticEqualitySet({0x105569d10, 0x1400001c100}, {{{0x14000050c90, 0x1, 0x1}}, {0x10556b088, 0x14000064fc0}, {0x10556b088, 0x14000064ff0}}, 0x14000065e30)
	/Users/sgoods/Hashicorp/terraform-plugin-framework/internal/fwschemadata/value_semantic_equality_set.go:27 +0x314
github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata_test.TestValueSemanticEqualitySet.func1(0x14000003a00)
	/Users/sgoods/Hashicorp/terraform-plugin-framework/internal/fwschemadata/value_semantic_equality_set_test.go:650 +0xa0
testing.tRunner(0x14000003a00, 0x14000010eb0)
	/opt/homebrew/Cellar/go/1.19.4/libexec/src/testing/testing.go:1446 +0x10c
created by testing.(*T).Run
	/opt/homebrew/Cellar/go/1.19.4/libexec/src/testing/testing.go:1493 +0x300


…icEqualitySetElements` when the number of new value elements is greater than prior value elements.
@SBGoods SBGoods requested a review from a team as a code owner June 14, 2023 18:15
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code updates look good to me, let's just ensure there is a developer friendly changelog entry. 👍 Maybe something like:

types/basetypes: Prevented panic with `ListTypableWithSemanticEquals` and `SetTypableWithSemanticEquals` when proposed new element count was greater than prior element count

@bflad bflad added the bug Something isn't working label Jun 14, 2023
@bflad bflad added this to the v1.3.1 milestone Jun 14, 2023
…equality-fix' into SBGoods/nested-element-semantic-equality-fix

# Conflicts:
#	.changes/unreleased/BUG FIXES-20230614-142449.yaml
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants