What is the minimum length of an aligned string ? Zero.
Since there is the "padding" (-4) code, that represents a zero-size string, it would have been tempting to bump the Type1 and Type2 strings by 1, extending the range to 256 or 65536 bytes. You can imagine the mess it would cause throughout the whole code... just for a tiny convenience.
But what is the maximum size of an aligned string ? The largest size field is in the Type3 "list" with a whole 32-bit number but there are two issues:
- the "fast" code only uses 24 bits due to the shift-based size computation. So a string can contain up to 16 million bytes.
- the "slow" code also needs to return an error code, which is a negative value, so the aStrA_length_slow function is an int, a signed value. This means that strings longer than 2 billion bytes will be interpreted as errors.
But seriously, who has ever seen or managed strings longer than 64K ?
If you encounter a string longer than 16M, then
- Either something is very wrong and you have hit a bug
- Somebody is trying to inject data
- You're trying to display or edit a very large file and you can't bother to process it by chunks.
All in all, it seems that the 16M imposed by the "fast" algorithm is reasonable. In fact, in the current code, the aStrA_length_slow function checks the bits 24-31 of the size as a canary that should be 0. Which is fine since the list format can't really have a similar canary as Types1 and 2.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.