fix: reject unexported struct fields at runtime#935
Merged
antonmedv merged 1 commit intoexpr-lang:masterfrom Feb 23, 2026
Merged
fix: reject unexported struct fields at runtime#935antonmedv merged 1 commit intoexpr-lang:masterfrom
antonmedv merged 1 commit intoexpr-lang:masterfrom
Conversation
When the type checker cannot determine a concrete struct type at compile time (e.g. ternary with mixed types), field access falls through to dynamic OpFetch at runtime. The Fetch function in vm/runtime and the get function in builtin/lib used FieldByNameFunc which matched unexported fields, then called Interface() on the resulting reflect.Value, causing a reflect error. Add IsExported() guards after FieldByNameFunc in both Fetch() and get() so unexported fields are never accessed via reflection. Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
29923f6 to
350894b
Compare
antonmedv
approved these changes
Feb 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the type checker cannot determine a concrete struct type at compile time (e.g. ternary with mixed types), field access falls through to dynamic
OpFetchat runtime. TheFetchfunction invm/runtimeand thegetfunction inbuiltin/libusedFieldByNameFuncwhich matched unexported fields, then calledInterface()on the resultingreflect.Value, causing:Add
IsExported()guards afterFieldByNameFuncin bothFetch()andget()so unexported fields are never accessed via reflection. Error output from tests:This pattern is part of the allow list in the fuzzing harness, so the issue should clear out once merged.
Relates to #934.