Subject: [Cbor] Decoding two-byte simple values

From: Jim Schaad <[email-masked]>
Date: Mon, 4 May 2020 08:31:15 -0700

The document says that an encoder MUST NOT encode simple values below 24 as
a two byte sequence.  The document is silent on the decode, but the tests in
appendix G list some examples that are encoded this way.  Question:  Should
this be tagged as a decode error?

Jim

---

From: Thiago Macieira <[email-masked]>
Date: Mon, 4 May 2020 08:36:18 -0700

> this be tagged as a decode error?

I do treat it as a decode error in TinyCBOR, but that check can be disabled by 
a non-default #define when building the code.

        case SimpleTypeInNextByte:
#ifndef CBOR_PARSER_NO_STRICT_CHECKS
            if (unlikely(it->extra < 32)) {
                it->type = CborInvalidType;
                return CborErrorIllegalSimpleType;
            }
#endif
            break;

This is the only check that can be disabled during the normal decode.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel System Software Products

---

From: Thiago Macieira <[email-masked]>
Date: Mon, 4 May 2020 08:38:25 -0700

>             if (unlikely(it->extra < 32)) {

And clearly this should be 24, not 32...

---

From: Carsten Bormann <[email-masked]>
Date: Mon, 4 May 2020 19:15:08 +0200

Hi Thiago,

> And clearly this should be 24, not 32...

No, actually 32.

(We goofed: » (To minimize confusion, only the values 32 to 255 are used.) «
Yeah right.  “Minimize confusion”.)

Section 3.3 in the editorial revision makes some of this a bit more clear:
Simple values with a two-byte encoding and a second byte of 0..31 are not well-formed.
See also the pseudocode, which now tests for that [2]:

    case 7: if (ai == 24 && val < 32) fail(); // bad simple

And the examples appendix is updated as well [3].

Please send in [4] any comments on this editorial revision very, very soon…

Grüße, Carsten

[1]: https://cbor-wg.github.io/CBORbis/draft-ietf-cbor-7049bis.html#rfc.section.3.3
[2]: https://cbor-wg.github.io/CBORbis/draft-ietf-cbor-7049bis.html#rfc.appendix.C
[3]: https://cbor-wg.github.io/CBORbis/draft-ietf-cbor-7049bis.html#rfc.appendix.A
[4]: https://github.com/cbor-wg/CBORbis/issues