google / flatbuffers

FlatBuffers: Memory Efficient Serialization Library
https://flatbuffers.dev/
Apache License 2.0
22.52k stars 3.19k forks source link

Bug: Wrong Condition for Checking the File Identifier [.NET/C#, master] #8308

Open abduelhamit opened 1 month ago

abduelhamit commented 1 month ago

The comments on Verifier.VerifyBuffer say:

When empty identifier is provided the identifier validation is skipped.

However, the condition for checking the file identifier only triggers if the provided identifier is "", which always leads to the ArgumentException:

FlatBuffers: file identifier must be length4

Changing (identifier.Length == 0) to (identifier.Length != 0) provides the right behavior.