Skip to content

Added canonical test cases for invalid packet input (#29)#167

Merged
hchataing merged 5 commits intogoogle:mainfrom
vasilybib1:feature/invalid-input-tests
Mar 3, 2026
Merged

Added canonical test cases for invalid packet input (#29)#167
hchataing merged 5 commits intogoogle:mainfrom
vasilybib1:feature/invalid-input-tests

Conversation

@vasilybib1
Copy link
Contributor

Summary

  • Add canonical test vectors for invalid packet inputs (trailing bytes, invalid enum values, invalid array sizes, invalid fixed values, invalid lengths)
  • Update all backend test harnesses (Rust, C++, Java, Python) to exercise invalid test vectors
  • Add missing validation checks to the C++ and Java backend decoders so they reject invalid inputs

Test Cases

15 invalid test vectors (LE), covering 5 error types across 6 packets:

InvalidLengthError (3 cases)

  • Packet_Scalar_Field with empty input - packet expects 8 bytes, gets 0
  • Packet_Scalar_Field with 000000 - packet expects 8 bytes, gets 3
  • Packet_Array_Field_ByteElement_ConstantSize with 0102 - expects 4-byte fixed array, gets 2

TrailingBytes (2 cases)

  • Packet_Scalar_Field with 000000000000000000 - 9 bytes for an 8-byte packet (1 extra)
  • Packet_Array_Field_ByteElement_ConstantSize with 0102030405 - 5 bytes for a 4-byte fixed array (1 extra)

InvalidEnumValueError (5 cases)

  • Packet_Enum_Field with 0x00 - not a valid tag in the closed enum
  • Packet_Enum_Field with 0x05 - falls between valid tags
  • Packet_Enum_Field with 0x7e - above all valid tags
  • Enum_Incomplete_Truncated_Closed with 0x02 and 0x07 - invalid values for a closed enum with range tags

InvalidFixedValue (4 cases)

  • Packet_FixedScalar_Field with 0x00 and 0x06 - wrong value for a field fixed to a specific scalar
  • Packet_FixedEnum_Field with 0x02 and 0x04 - wrong value for a field fixed to a specific enum tag

InvalidArraySize (1 case)

  • Packet_Array_Field_ScalarElement_VariableSize with 03010203 - size field says 3 bytes but element width is 2, so 3 % 2 != 0

The BE test vectors mirror these except Enum_Incomplete_Truncated_Closed (LE only), giving 12 BE cases.

Closes #29

@hchataing
Copy link
Collaborator

Thanks for the patch :)
Good to merge on my side.
Waiting for @jameseidson to validate the changes to the Java backend.

@jameseidson
Copy link
Collaborator

LGTM, thanks for the patch!

@hchataing hchataing self-requested a review March 3, 2026 08:35
@hchataing hchataing enabled auto-merge (squash) March 3, 2026 08:39
@hchataing hchataing disabled auto-merge March 3, 2026 08:40
@hchataing hchataing merged commit 19fbf41 into google:main Mar 3, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add canonical test cases for invalid packet inputs

3 participants