Skip to content

Fix EqualExportedValues on recursive values#1916

Open
cyphercodes wants to merge 1 commit into
stretchr:masterfrom
cyphercodes:fix-equal-exported-recursive
Open

Fix EqualExportedValues on recursive values#1916
cyphercodes wants to merge 1 commit into
stretchr:masterfrom
cyphercodes:fix-equal-exported-recursive

Conversation

@cyphercodes

Copy link
Copy Markdown

Summary

Fix EqualExportedValues so copying exported fields terminates for recursive values.

Changes

  • Track visited pointer/slice/map values while copying exported fields.
  • Reuse in-progress copies when a recursive value is encountered.
  • Add a regression test for self-referential struct pointers with differing unexported fields.

Motivation

copyExportedFields recursed indefinitely on pointer cycles, causing EqualExportedValues to time out or overflow the stack for recursive data structures.

Exact test commands run:

  • go test ./assert -run TestEqualExportedValuesRecursiveStruct -count=1 -timeout=3s (failed before the fix; timed out reproducing the bug)
  • go test ./assert -run 'TestEqualExportedValuesRecursiveStruct|TestEqualExportedValues|TestObjectsExportedFieldsAreEqual|TestCopyExportedFields' -count=1
  • go test ./assert -count=1
  • go test ./... -count=1
  • git diff --check

Related issues

Fixes #1915

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EqualExportedValues overflow the stack on recursive data structures

1 participant