Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.8.0 #377

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- name: Generate and install zcbor package
run: |
python build bdist_wheel
pip install dist/zcbor-0.7.99-py3-none-any.whl
pip install dist/zcbor-0.8.0-py3-none-any.whl
pip uninstall -y zcbor
pip install -e .

Expand Down Expand Up @@ -129,10 +129,15 @@ jobs:
sudo apt update
sudo apt install -y afl++

- name: Run everything fuzz tests
working-directory: tests/fuzz
run: |
./test-afl.sh 2400 64 everything

- name: Run manifest12 fuzz tests
working-directory: tests/fuzz
run: |
./test-afl.sh 3200 64 manifest12
./test-afl.sh 800 64 manifest12

- name: Run pet fuzz tests
working-directory: tests/fuzz
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ python3 <zcbor base>/zcbor/zcbor.py validate -c <CDDL description file> -t <whic
python3 <zcbor base>/zcbor/zcbor.py convert -c <CDDL description file> -t <which CDDL type to expect> -i <input data file> -o <output data file>
```

You can see an example of the conversions in [tests/cases/yaml_compatibility.yaml](tests/cases/yaml_compatibility.yaml) and its CDDL file [tests/cases/yaml_compatibility.cddl](tests/cases/yaml_compatibility.cddl).

Importing zcbor in a Python script
----------------------------------

Expand Down
4 changes: 3 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# zcbor v. 0.7.99
# zcbor v. 0.8.0 (2024-01-09)

Any new bugs, requests, or missing features should be reported as [Github issues](https://github.com/NordicSemiconductor/zcbor/issues).

Expand Down Expand Up @@ -51,6 +51,8 @@ Any new bugs, requests, or missing features should be reported as [Github issues
* zcbor.py: Adjust the lower bound on negative numbers.
* zcbor_encode, zcbor_decode: fix double promotion warnings
* zcbor_print.h: Add missing errors to zcbor_error_str()
* zcbor_print.h: Fix memcmp expression
* zcbor.py: DataTranslator: fix type checking

## Unsupported CDDL features
Not all features outlined in the CDDL specs [RFC8610](https://datatracker.ietf.org/doc/html/rfc8610), [RFC9090](https://datatracker.ietf.org/doc/html/rfc9090), and [RFC9165](https://datatracker.ietf.org/doc/html/rfc9165) are supported by zcbor.
Expand Down
2 changes: 1 addition & 1 deletion include/zcbor_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static void zcbor_print_compare_strings_diff(const uint8_t *str1, const uint8_t
{
bool printed = false;
for (uint32_t i = 0; i <= size / 16; i++) {
if (memcmp(&str1[i*16], &str2[i*16], MIN(16, (size - i*16)) != 0)) {
if (memcmp(&str1[i*16], &str2[i*16], MIN(16, (size - i*16))) != 0) {
zcbor_do_print("line %d (char %d)\r\n", i, i*16);
zcbor_print_compare_lines(&str1[i*16], &str2[i*16],
MIN(16, (size - i*16)));
Expand Down
2 changes: 1 addition & 1 deletion samples/pet/include/pet_decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*
* Generated using zcbor version 0.7.99
* Generated using zcbor version 0.8.0
* https://github.com/NordicSemiconductor/zcbor
* Generated with a --default-max-qty of 3
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/pet/include/pet_encode.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*
* Generated using zcbor version 0.7.99
* Generated using zcbor version 0.8.0
* https://github.com/NordicSemiconductor/zcbor
* Generated with a --default-max-qty of 3
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/pet/include/pet_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*
* Generated using zcbor version 0.7.99
* Generated using zcbor version 0.8.0
* https://github.com/NordicSemiconductor/zcbor
* Generated with a --default-max-qty of 3
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/pet/pet.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SPDX-License-Identifier: Apache-2.0
#
# Generated using zcbor version 0.7.99
# Generated using zcbor version 0.8.0
# https://github.com/NordicSemiconductor/zcbor
# Generated with a --default-max-qty of 3
#
Expand Down
2 changes: 1 addition & 1 deletion samples/pet/src/pet_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*
* Generated using zcbor version 0.7.99
* Generated using zcbor version 0.8.0
* https://github.com/NordicSemiconductor/zcbor
* Generated with a --default-max-qty of 3
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/pet/src/pet_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*
* Generated using zcbor version 0.7.99
* Generated using zcbor version 0.8.0
* https://github.com/NordicSemiconductor/zcbor
* Generated with a --default-max-qty of 3
*/
Expand Down
33 changes: 33 additions & 0 deletions tests/cases/everything.cddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
EverythingUnion = (
uint /
uint_single: 10 /
uint_range: 15..20 /
nint /
nint_single: -2 /
nint_range: -10..-5 /
bstr /
bstr_single: 'foo' /
bstr_size: bstr .size 3 /
bstr_cbor: bstr .cbor uint /
tstr /
tstr_single: "bar" /
tstr_size: tstr .size 5 /
list: [
+uint,
+nint
] /
map: {
(1 => "one") / (2 => "two")
} /
repeated: *uint /
bool /
bool_single: true /
nil /
undefined /
float16 /
float16_single: 3.140625 /
float32 /
float32_single: 1.10004723072052 /
float64 /
float64_single: -6.28
)
25 changes: 25 additions & 0 deletions tests/cases/everything_example0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
- 1
- 10
- 16
- -1
- -2
- -6
- {zcbor_bstr: "001122334455667788"}
- {zcbor_bstr: "666f6f"}
- {zcbor_bstr: "332211"}
- {zcbor_bstr: 42}
- hello_world
- bar
- five5
- {zcbor_keyval1: {key: 1, val: "one"}}
- false
- true
- null
- [zcbor_undefined]
- 0.5
- 3.140625
- 0.51
- 1.10004723072052
- 2.71
- -6.28
- []
32 changes: 32 additions & 0 deletions tests/cases/everything_example1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
- 0x1234567890
- 10
- 17
- -0x9876543210
- -2
- -7
- {zcbor_bstr: "00112233445566778899aabbccddeeffeeddccbbaa99887766554433221100"}
- {zcbor_bstr: "666f6f"}
- {zcbor_bstr: "123456"}
- {zcbor_bstr: 0xffffffffff}
- Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
- bar
- ÆØÅ?/
- {zcbor_keyval1: {key: 2, val: "two"}}
- 0x80
- 0x8000
- 0x800000
- 0x80000000
- 0x8000000000
- 0x800000000000
- 0x80000000000000
- false
- true
- null
- [zcbor_undefined]
- 1024.0
- 3.140625
- 65536.0
- 1.10004723072052
- 12345678987.654321
- -6.28
- {"hello": "world"}
27 changes: 27 additions & 0 deletions tests/fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,33 @@ elseif (${TEST_CASE} STREQUAL manifest12)
include(${PROJECT_BINARY_DIR}/manifest12.cmake)
target_link_libraries(fuzz_target PRIVATE manifest12)

elseif (${TEST_CASE} STREQUAL everything)
execute_process(
COMMAND zcbor
code
-c ${CMAKE_CURRENT_LIST_DIR}/../cases/everything.cddl
--output-cmake ${PROJECT_BINARY_DIR}/everything.cmake
-t EverythingUnion
-d
)

foreach(n RANGE 0 1)
execute_process(
COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/../../zcbor/zcbor.py
convert
--cddl ${CMAKE_CURRENT_LIST_DIR}/../cases/everything.cddl
--input ${CMAKE_CURRENT_LIST_DIR}/../cases/everything_example${n}.yaml
--yaml-compatibility
-t EverythingUnion
--output ${PROJECT_BINARY_DIR}/fuzz_input/input${n}.cbor
--output-as cbor
)
endforeach()

target_sources(fuzz_target PRIVATE fuzz_everything.c)
include(${PROJECT_BINARY_DIR}/everything.cmake)
target_link_libraries(fuzz_target PRIVATE everything)

else()
message(FATAL_ERROR "Invalid test case")
endif()
12 changes: 12 additions & 0 deletions tests/fuzz/fuzz_everything.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "everything_decode.h"
#include "main_entry.h"

bool fuzz_one_input(const uint8_t *data, size_t size)
{
size_t payload_len_out = 0;
struct EverythingUnion_r result;
bool ret = cbor_decode_EverythingUnion(data, size,
&result,
&payload_len_out);
return ret;
}
2 changes: 1 addition & 1 deletion tests/fuzz/test-afl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: Apache-2.0
#

echo "Usage: $0 <seconds to run> <bit width>"
echo "Usage: $0 <seconds to run> <bit width> <test case>"

# For convenience (use for extra checks):
# export AFL_USE_ASAN=1
Expand Down
2 changes: 1 addition & 1 deletion zcbor/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.99
0.8.0
27 changes: 15 additions & 12 deletions zcbor/zcbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,32 +1323,35 @@ def _check_tag(self, obj):
# Return our expected python type as returned by cbor2.
def _expected_type(self):
return {
"UINT": lambda: int,
"INT": lambda: int,
"NINT": lambda: int,
"FLOAT": lambda: float,
"TSTR": lambda: str,
"BSTR": lambda: bytes,
"NIL": lambda: type(None),
"UNDEF": lambda: type(undefined),
"UINT": lambda: (int,),
"INT": lambda: (int,),
"NINT": lambda: (int,),
"FLOAT": lambda: (float,),
"TSTR": lambda: (str,),
"BSTR": lambda: (bytes,),
"NIL": lambda: (type(None),),
"UNDEF": lambda: (type(undefined),),
"ANY": lambda: (int, float, str, bytes, type(None), type(undefined), bool, list, dict),
"BOOL": lambda: bool,
"BOOL": lambda: (bool,),
"LIST": lambda: (tuple, list),
"MAP": lambda: dict,
"MAP": lambda: (dict,),
}[self.type]()

# Check that the decoded object has the correct type.
def _check_type(self, obj):
if self.type not in ["OTHER", "GROUP", "UNION"]:
exp_type = self._expected_type()
self._decode_assert(
isinstance(obj, exp_type),
f"{str(self)}: Wrong type of {str(obj)}, expected {str(exp_type)}")
type(obj) in exp_type,
f"{str(self)}: Wrong type ({type(obj)}) of {str(obj)}, expected {str(exp_type)}")

# Check that the decode value conforms to the restrictions in the CDDL.
def _check_value(self, obj):
if self.type in ["UINT", "INT", "NINT", "FLOAT", "TSTR", "BSTR", "BOOL"] \
and self.value is not None:
value = self.value
if self.type == "BSTR":
value = self.value.encode("utf-8")
self._decode_assert(
self.value == obj,
f"{obj} should have value {self.value} according to {self.var_name()}")
Expand Down