When calculating the maximum length of the bstr, there are certain
payload lengths which cannot be filled by a bstr (incl. header and
payload). One of these lengths is 258, since a 255 byte payload gets a
2-byte header (total 257) and a 256 byte payload gets a 3-byte header
(total 259), i.e. there is no combination that gives 258 bytes. The same
applies to tota lengths of 25, 65539-65540, and 4294967300-4294967304
The previous code tried to find the start of the string by extrapolating
from the end of the payload, but this gave the wrong answer for the
cases described above.
The bug caused CBOR-encoded bstrs to lose a byte.
When calculating the maximum length of the bstr, there are certain payload lengths which cannot be filled by a bstr (incl. header and payload). One of these lengths is 258, since a 255 byte payload gets a 2-byte header (total 257) and a 256 byte payload gets a 3-byte header (total 259), i.e. there is no combination that gives 258 bytes. The same applies to tota lengths of 25, 65539-65540, and 4294967300-4294967304
The previous code tried to find the start of the string by extrapolating from the end of the payload, but this gave the wrong answer for the cases described above.
Add a test that tests some of the cases.