mirror of
https://github.com/nspcc-dev/neofs-sdk-go.git
synced 2026-03-01 04:29:18 +00:00
Checking for the fields' presence should not be done by unmarshalers #236
Labels
No labels
I2
I3
I4
S1
S2
S3
S4
U0
U1
U2
U2
U2
U3
U4
blocked
bug
client
config
discussion
documentation
enhancement
epic
feature
go
good first issue
help wanted
performance
pool
question
security
task
test
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
nspcc-dev/neofs-sdk-go#236
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @cthulhu-rider on GitHub (Nov 19, 2024).
most of the lib data structures provide
Unmarshal/UnmarshalJSONinterface. Implementations do not check for presence of the fields required by the protocol (example). However, since structure is fully decoded and then verified (as in the example), checking of complex fields requires callingReadFromV2(nspcc-dev/neofs-sdk-go@2da6182d23/bearer/bearer.go (L48)) which expects all required fields to be setthis makes it impossible to set partially filled complex sub-field, encode the whole message, and then decode without an error. Although such a process does not seem to be in demand, in general it can cause a problem. Let's say in tests at the moment
Steps to Reproduce
Current Behavior
Expected Behavior
passed test
being a user, i expect to set the instance in any form (*), encode it and successfully decode it. I also expect to be able to check any field for presence
(*) mostly without specifying required fields. I still expect decoder to make sanity checks for some type of fields. For example, fixed-len IDs must have the exact size: this is just cuz project type system is stronger than Protocol Buffers. If protobuf would have fixed-len array type, we would use it and decoding would fail on the protolib stage
Possible Solution
i see 2 ones:
ReadOptionalFromV2which will check specified fields only (e.g. that IDs have exact bytelen) and use it instead ofReadFromV2Context
https://github.com/nspcc-dev/neofs-node/pull/3005#issuecomment-2483371807
Regression
not really. For example, this became actual for
Objectafter https://github.com/nspcc-dev/neofs-sdk-go/pull/634/commits/3c47093ae4c28b62afba3e3f34bb270d39cf3137, but there were no checks at all before@roman-khimov commented on GitHub (Nov 19, 2024):
Who cares about these problems except for obscure tests? Current behavior is more suitable for generic users, so it should stay. Tests can find some ways to break things when they need to.
@cthulhu-rider commented on GitHub (Nov 19, 2024):
any user passing data back and forth i'd say. The main goal of this issue is to highlight current that at the moment the behavior is not strictly fixed, and can sometimes change in one direction or another. I suggest to choose and fix the one
for example, https://github.com/nspcc-dev/neofs-node/pull/3005#issuecomment-2483371807 (p.3) encountered a regression when tested object has session token w/o an issuer (required by the protocol). In the latest lib version, object cannot be received due to recently added
invalid header: invalid session token: missing session issuerdecoding error. Previously, there was no such errorso, protocol requirement to specify the session issuer now also affects binary objects stored by nodes:
in total, smth should be done anyway:
im leaning towards the 1 as its more flexible for the general-purpose library
@roman-khimov commented on GitHub (Nov 20, 2024):
My expectation is that no real objects have these problems, so we can catch everything needed at decoding level and have an always nice object structures. Creating an object that violates basic rules must be hard enough for most checks to be not needed at the encoding stage at the same time.
@cthulhu-rider commented on GitHub (Nov 25, 2024):
i think all requirements imposed on the object and returned by
Unmarshalshould be transparent and checked before storing the object. This can be covered by SDK docs and changes in the storageagain, if
Putreturns no error, i dont expect an error fromGet. Original issue's context is exactly about this@roman-khimov commented on GitHub (Nov 25, 2024):
That's a correct expectation. And we have two sides of it:
The latter is different in that if some node creates and stores a bogus object it's this node's problem. It shouldn't do this.