Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Update lisk-codec to disallow additional or missing data while decoding #7047

Closed
Tracked by #7210
shuse2 opened this issue Feb 23, 2022 · 1 comment · Fixed by #7329
Closed
Tracked by #7210

Update lisk-codec to disallow additional or missing data while decoding #7047

shuse2 opened this issue Feb 23, 2022 · 1 comment · Fixed by #7329

Comments

@shuse2
Copy link
Collaborator

shuse2 commented Feb 23, 2022

Description

Currently, x == encode(decode(x)) is enforced at processor.
However, for efficiency and consistency, this should be implemented in decode of the codec.

While decoding,

  • It should fail if existing field number in the schema does not exist in the binary, except for array. (empty array is allow not to appear in the binary)
  • It should fail if additional data exist in the binary regardless of position

Additionally, missing tests in the acceptance criteria should be implemented.

Acceptance Criteria

  • Decoding sint... values (using readSInt...) that are out of range. Expected: Decoding should fail
  • Decoding a boolean value where the value is a byte unequal to 0x00 and 0x01. Expected: Decoding should fail
  • Encoding a string that contains some non-ASCII characters. Expected: Encoding succeeds
  • Decoding a string that contains some non-ASCII characters. Expected: Decoding succeeds
  • Encoding empty array, where the datatype of the items implies non-packed encoding, e.g. string. Expected: binary message is empty
  • Schema contains a property of type array, where the datatype of the items implies non-packed encoding, e.g. string. The binary message is empty Expected: Decoded to the property that contains an empty array.
  • Object to encode has a property that is not contained in the schema. Expected: Encoding fails
  • Decoding a binary message that does not respect the fieldNumber order. Expected: Decoding fails
  • Decoding a binary message where one fieldNumber is used twice in the binary message. The fieldNumber order is repected, i.e., the two key-value pairs with the same fieldNumber must be adjacent in the binary message. Expected: Decoding fails
  • Encoding an object where the fieldNumbers in the schema are not sequential Expected: Encoding succeeds
  • Decoding a binary message where the fieldNumbers in the schema are not sequential Expected: Decoding succeeds
  • Decoding a binary message where one required property (not of type array) is not contained in the binary message Expected: Decoding fails
  • Decoding a binary message that contains a field number not present in the schema. Expected: Decoding fails
  • Decoding a binary message that contains some bytes at the end that cannot be decoded to some key-value pairs. E.g., a binary message contatenated with the byte 0x00. Expected: Decoding fails
  • A binary message contains a key-value pair for a property of type array for which packed encoding is used (for example boolean), and the value exist as empty bytes. Expected: Decoding fails

Additional Information

Most of the tests should be covered by adding protocol spec.

@shuse2
Copy link
Collaborator Author

shuse2 commented Jul 26, 2022

Object to encode has a property that is not contained in the schema. Expected: Encoding fails

This will not fail. During the encoding, properties which is not in the schema will be ignored.

@milenagojkovic milenagojkovic moved this from In Progress to Pending Review in Lisk SDK Version 6.0.0 Jul 27, 2022
Repository owner moved this from Pending Review to Done in Lisk SDK Version 6.0.0 Jul 29, 2022
ishantiw added a commit that referenced this issue Jul 29, 2022
Update lisk-codec to disallow decoding additional fields - Closes #7047
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants