-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zcbor_encode.c: Fix a length bug in zcbor_bstr_end_decode()
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 total 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. But also, the remaining_str_len was suboptimally implemented, so a few more cases were also wrong. Fix zcbor_bstr_end_encode(), remaining_str_len(), and add tests that test both functions Signed-off-by: Øyvind Rønningstad <[email protected]>
- Loading branch information
1 parent
a9945b7
commit d5662e2
Showing
4 changed files
with
131 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters