Skip to content

Avoid using string fields for binary data #3093

@jasonpaulos

Description

@jasonpaulos

Summary

Recently the field Logs []string was added to EvalDelta. This field is meant to hold arbitrary binary data, but because it was declared with []string, when encoding into JSON the data is interpreted as UTF-8. If instead it were declared as [][]byte, our encoder would base64 encode the contents when encoding into JSON. For this reason, it's necessary to use []byte over string for binary data in all cases.

Scope

  • Add a unit test which uses reflection and recursion to examine all fields referenced from bookkeeping.Block. If the field is a string and we don't have a specific exception for it, error. This will prevent us from accidentally adding string fields going forward.
  • For existing string fields, create exceptions so the test passes with the current structs. However, investigate whether converting these fields to byte slices has any effect on their msgpack encoding -- if not, then convert them to byte slices to eliminate all strings from the structs.
    • Msgpack uses different byte prefixes to distinguish between strings and binary data, so we cannot migrate the existing string instances to []byte without changing the canonical encoding of these structures.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions