-
Notifications
You must be signed in to change notification settings - Fork 1
state: preserve private reflected field access during migration #28
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,10 @@ import ( | |
| "unsafe" | ||
| ) | ||
|
|
||
| // Go 1.26 reflect/value.go: flagStickyRO and flagEmbedRO have distinct Field | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor consistency: the rest of the codebase pins ABI-dependent comments to the exact toolchain ("Go 1.26.6", matching |
||
| // propagation rules. Keep both bits instead of collapsing them to CanInterface. | ||
| const reflectValueReadOnlyMask = uint64(1<<5 | 1<<6) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The two read-only bits are documented as "distinct" but the mask uses bare magic numbers. Consider named constants composed into the mask, e.g.: const (
flagStickyRO = uint64(1 << 5)
flagEmbedRO = uint64(1 << 6)
)
const reflectValueReadOnlyMask = flagStickyRO | flagEmbedROThis makes the "keep both bits" intent self-evident and pairs naturally with the bare |
||
|
|
||
| // reflectValueRWAddr is equivalent to obj.Addr(), except that the returned | ||
| // reflect.Value is usable in assignments even if obj was obtained by the use | ||
| // of unexported struct fields. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -769,7 +769,11 @@ func (es *encodeState) encodeObject(obj reflect.Value, how encodeStrategy, dest | |
| return | ||
| } | ||
| if !value.CanInterface() { | ||
| Failf("reflect.Value has restricted access") | ||
| // Clear access restrictions on this Value copy only. The restored | ||
| // view must retain them even though state can traverse private data. | ||
| flag := reflect.ValueOf(&value).Elem().FieldByName("flag") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
| encoded.ReadOnly = flag.Uint() & reflectValueReadOnlyMask | ||
| reflectValueRWAddr(flag).Elem().SetUint(flag.Uint() &^ reflectValueReadOnlyMask) | ||
| } | ||
| encoded.Addressable = value.CanAddr() | ||
| if encoded.Addressable { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The added
|| x.ReadOnly != 0clause is correct — a zeroreflect.Valuecan't carry read-only bits, so a nonzeroReadOnlyhere signals a corrupt/malicious stream — but bundled withx.Addressableit reads as unexplained. A short inline comment noting why would help. Nit.