This repository has been archived on 2026-09-06 . You can view files and clone it. You cannot open issues or pull requests or push a commit.
4682eaa1e068f0fdcf2f2806a6b6fdb7fa831894
When value_to_pretty is called with recursionsLeft=0 and an Array or Map
type, container_to_pretty is called with recursionsLeft - 1 = -1. This
breaks the recursion limit check.
In practice, this can be triggered with a CBOR data containing 1023
Arrays, a Tag and many more Arrays:
$ python3 -c 'import sys;sys.stdout.buffer.write(b"\x9f" * 1023 + b"\xc0\x9f" + b"\x9f" * 100000 + b"\xff" * 101024)' | ./bin/cbordump
Segmentation fault (core dumped)
This segmentation fault is due to the stack growing too much, due to the
quantity of recursive calls.
Fix this by reporting a proper error when recursionsLeft <= 0, instead
of when recursionsLeft == 0. The same input now produces:
[_ [_ [_ ... [_ 0([
-: internal error: too many nested containers found in recursive function
_ <nesting too deep, recursion stopped>
Moreover, using fewer nested arrays works fine:
$ python3 -c 'import sys;sys.stdout.buffer.write(b"\x9f" * 1023 + b"\xc0\x9f" + b"\x9f" * 1024 + b"\xff" * 2048)' |./bin/cbordump
[_ [_ [_ ... [_ 0([_ <nesting too deep, recursion stopped>])] ... ]]]
Also modify the test when formatting CborTagType to ensure
value_to_pretty is never called with a negative recursionsLeft.
Concise Binary Object Representation (CBOR) Library --------------------------------------------------- To build TinyCBOR: make If you want to change the compiler or pass extra compiler flags: make CC=clang CFLAGS="-m32 -Oz" LDFLAGS="-m32" Documentation: https://intel.github.io/tinycbor/current/
Languages
C
50.3%
C++
45.9%
CMake
2.1%
Perl
1.3%
Shell
0.3%
Other
0.1%