Closed InsertCreativityHere closed 11 months ago
The decoding must be strict. Receiving 5 for a bool is an error.
According to the C# docs, only the lowest bit of a bool is relevant in memory: https://learn.microsoft.com/en-us/dotnet/api/system.boolean?view=net-7.0#work-with-booleans-as-binary-values The other bits are free to be whatever, and C# doesn't care.
^ This is just in reference to a question. I agree that the decoder should be strict.
The encoding referece states that bools must be
0
forfalse
or1
fortrue
, and that all other values are invalid.However, the logic for
DecodeBool
doesn't enforce this part of the spec. It treats0
asfalse
, and any other value astrue
. Should we be better enforcing the spec and rejecting values like2
as invalid, instead of silently treating them as valid?For reference: https://github.com/icerpc/icerpc-csharp/blob/fbd611d007b8cadfc995e1474885262307decd1b/src/ZeroC.Slice/SliceDecoder.cs#L130-L131
Or alternatively, should we amend the spec to follow icerpc-csharp's behavior (
0
isfalse
, otherwisetrue
). This would be a strict relaxing of the spec, and hence backwards compatible. It would simplify the job of a decoder (since it's impossible to decode an invalid bool with this change), but might be 'less safe'.