ubjson / universal-binary-json

Community workspace for the Universal Binary JSON Specification.
115 stars 12 forks source link

Negative lengths for strings or containers #118

Open to-miz opened 1 year ago

to-miz commented 1 year ago

The specification doesn't say how to handle negative values in lengths. I propose that it should be handeled as an error, but this needs to be specified, otherwise parsers will disagree on how to handle this case.

I checked a couple of C/C++ libraries, and they seem to silently cast the value to a size_t and allocating memory, resulting in either crashes or errors. The missing specification seems to have resulted in unsafe implementations.

to-miz commented 1 year ago

Update: I found [count] A count must be >= 0. under "optimized-format", see https://ubjson.org/type-reference/container-types/#optimized-format

So there is an annotation for optimized containers but not for strings.