Re: [Cbor] 65-bit negatives, big nums conflict between CDE and dCBOR drafts?

Wolf McNally <wolf@wolfmcnally.com> Wed, 10 April 2024 07:30 UTC

Return-Path: <wolf@wolfmcnally.com>
X-Original-To: cbor@ietfa.amsl.com
Delivered-To: cbor@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 28F45C14F5FE for <cbor@ietfa.amsl.com>; Wed, 10 Apr 2024 00:30:16 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.894
X-Spam-Level:
X-Spam-Status: No, score=-1.894 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=wolfmcnally-com.20230601.gappssmtp.com
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id E9VGr3h2hsKE for <cbor@ietfa.amsl.com>; Wed, 10 Apr 2024 00:30:11 -0700 (PDT)
Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id AF4A3C14F5FA for <cbor@ietf.org>; Wed, 10 Apr 2024 00:30:11 -0700 (PDT)
Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1e411e339b8so23388655ad.3 for <cbor@ietf.org>; Wed, 10 Apr 2024 00:30:11 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wolfmcnally-com.20230601.gappssmtp.com; s=20230601; t=1712734211; x=1713339011; darn=ietf.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=ZA2meFjmawFburC9rZEz6lfubdXJKbFwQgH9zsDcHd8=; b=B0Q8zPwPXbs1RmCx/LnbHtQj8L/n/3SnStfXDUeZ8NxCp2syZJpXIjs/ZI3+9Wa1yc M9d9S/Y+6CIO5obU8tMZAXUHl1eKqCDVqiFs6cvbHUh/MoWASlou/ZLLGZ0wHNUTWFkn QVAYJoX/opFCn5KMw7FPKWBNKxCJWKmwdkRo0Cnkat8vVRBAOlnWal/yNgwWbyUjjDPW xiPpis2PvftDwbx6uygHlQUkvG0xTPgZSCzeRoY4QrOhmg1RjptC88FnZTpsTBRuUXXz MOoOdF0o4/9zf9q6YNQ+hSgKu5BfcYeIURJKS9a4gcz1RnG3lfQUUOnzT3vCdTpYD8jj 31dA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712734211; x=1713339011; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZA2meFjmawFburC9rZEz6lfubdXJKbFwQgH9zsDcHd8=; b=TmZI/tlZwN+roHFxdGG0K6JWUxZkqqJ6LFy85sZXwad+/wAg57M1ZJyUNy3qLFHPwy a7vpHLgAgQv5R2xU6ZuQr9K3Fd2h5pSEMuAVeYqW3fDLT174wdZ/yOddpOHSHDkYc4As prYMrWQFB6VpS/CEQIbIIVVm9AQQDcuiPxc3nK14frLd3Ne0kLjngNKZy8RyT0YY1XKF Ha0Q/bHS60MbJurMvRyL3GNDvyCrCU4o3RZaCMp/+4ggEqbHOAH3Y0XhRGgruq8Zeqsd eKByqpgZB9Wyz0rIe1DhNaQ8Shk/9G+jHScYtrEApF4AzIiR+pDtFuoUUQtS6C+t5QFi nfWw==
X-Forwarded-Encrypted: i=1; AJvYcCUxQDwvJzsTV6wswzwEM8YefBAfkLCiPXX/pwjS981ZSt+MtvJfKAWqAcreyVgcQ0V1kN2Z7W0hJgQo85UC
X-Gm-Message-State: AOJu0Ywiifrhg4mMPIYa3hzR8iaG9SsSvWm4suPtUCSjJw9hxuw5TEpc 8pr0EcZQsSymY+y/KLVDrhhn/8PvTH6+367/rY7n2HnUzNjDrUKTFMG9SajWpHA=
X-Google-Smtp-Source: AGHT+IFYZBiWHQaY39bh871OgSTkgkLD3uFDclFCy6m/MTkmzixHJxSUWOLe4j7QkIPbisnZDaYyiQ==
X-Received: by 2002:a17:902:db08:b0:1e2:718c:61e with SMTP id m8-20020a170902db0800b001e2718c061emr2198489plx.27.1712734210666; Wed, 10 Apr 2024 00:30:10 -0700 (PDT)
Received: from smtpclient.apple ([45.132.159.144]) by smtp.gmail.com with ESMTPSA id d10-20020a170902ceca00b001e501266800sm538462plg.184.2024.04.10.00.30.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2024 00:30:10 -0700 (PDT)
From: Wolf McNally <wolf@wolfmcnally.com>
Message-Id: <41F8F4E2-9C51-4D83-B698-C47B75876E8C@wolfmcnally.com>
Content-Type: multipart/alternative; boundary="Apple-Mail=_A757D98A-BC7A-42B0-A701-67C2E6E7B380"
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.500.171.1.1\))
Date: Wed, 10 Apr 2024 00:29:58 -0700
In-Reply-To: <DFAF11BE-6D5B-404F-A0CE-0DA263835EB0@island-resort.com>
Cc: Carsten Bormann <cabo@tzi.org>, "cbor@ietf.org" <cbor@ietf.org>, Christopher Allen <christophera@lifewithalacrity.com>, Shannon Appelcline <shannon.appelcline@gmail.com>
To: "lgl island-resort.com" <lgl@island-resort.com>
References: <775D5398-1A78-4255-B337-B9B25ED03ED3@island-resort.com> <1aea13ce-9646-41cb-8f1a-5a249d08e693@gmail.com> <32A30872-2701-49E6-AAFE-4E8CC7EA4C31@island-resort.com> <D20445F4-33E9-40E6-8485-7421D7690521@tzi.org> <DFAF11BE-6D5B-404F-A0CE-0DA263835EB0@island-resort.com>
X-Mailer: Apple Mail (2.3774.500.171.1.1)
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/YGaHLOJuwhHj8EFqT4CRgATFp3U>
Subject: Re: [Cbor] 65-bit negatives, big nums conflict between CDE and dCBOR drafts?
X-BeenThere: cbor@ietf.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: "Concise Binary Object Representation \(CBOR\)" <cbor.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/cbor>, <mailto:cbor-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cbor/>
List-Post: <mailto:cbor@ietf.org>
List-Help: <mailto:cbor-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/cbor>, <mailto:cbor-request@ietf.org?subject=subscribe>
X-List-Received-Date: Wed, 10 Apr 2024 07:30:16 -0000

LL,

It has been our intention from day one that nothing in dCBOR shall conflict with the established requirements of CBOR: all dCBOR MUST be decodable as plain CBOR, and now by extension CDE.

Further, it was never our expectation that -2^64 would be encoded as a float, and in fact we deliberately set no such expectations.

So if dCBOR’s current proscription of type 1 negative 65-bit integers indeed conflicts with this, then it must go. Obviously, this leaves a dangling range of basic integers expressible in dCBOR that are not expressible in either signed or unsigned 64-bit machine integers and which dCBOR (indeed all CBOR) implementations that do not support wider integers will have to reject.

But that, as they say, is the way the cookie crumbles. At least this has the resolution that there is still exactly one way to encode each integer value.

I will be updating the dCBOR I-D and our reference implementations accordingly.

~ Wolf

> On Apr 8, 2024, at 2:29 PM, lgl island-resort.com <lgl@island-resort.com> wrote:
> 
> Right. It’s a requirement. Missed it because it is not mentioned in the section on preferred serialization and I didn’t think to grep RFC 8949 for “preferred".
> 
> (My plan is to read the cbor-diag ruby code in addition to RFC 8949 next time; have started checking other CBOR implementations; so far only cbor-diag and QCBOR implement the big number tags).
> 
> 
> How should -2^64 be encoded in dCBOR?
> 
> Preferred serialization (both RFC 8949 and draft-ietf-cbor-cde-02) requires it to be a type 1 65-bit negative integer. This is in conflict with the prohibition of 65-bit negatives in dCBOR. It is a conflict because dCBOR requires compliance with CDE which requires compliance with preferred serialization.
> 
> Clearly the dCBOR inventors expected it would be encoded as a float.
> 
> However, I think the answer here has to be that dCBOR has to drop the prohibition of 65-bit negatives and that implementations will have to deal with the special case.
> 
> The alternative is to change the requirement in RFC 8949 with errata or a new RFC or something. The problem here is not that big. It’s just more code for a special case that some of us have to write.
> 
> 
> 
> The pseudo-normative rules for Preferred Serialization I previously shared need to be amended:
> 
> If big numbers (tags 2 and 3) are supported, integers that can be encoded as type 0 and 1 MUST NOT be encoded as tag 2 or 3.
> 
> If integers more negative than -2^63 are supported, then decoders MUST accept and correctly process the range [-2^64, -2^63 - 1] encoded as type 1.
> 
> 
> 
> A few more thoughts.
> 
> Any library that does preferred serialization and supports integers beyond -2^63 MUST send 65-bit negs. Some decoders won’t be prepared for this. QCBOR 1.x for example. But, it’s the law of the land.
> 
> It’s super easy to unify with big nums in Ruby or Python because the languages support big integers. The cbor-diag ruby code is super clean and simple.
> 
> This begs the question as to why big floats aren’t unified with regular floats in preferred serialization. Python has big floats. Ruby, however, has big decimals.
> 
> There’s no more rules for Preferred Serialization, right? Grep of RFC 8949 doesn’t turn up any.
> 
> There’s another interesting question for me — what should an implementation that supports both tag 2/3 AND dCBOR do for 2^66 and such Dunno yet.
> 
> LL
> 
> 
> 
> 
> 
>> On Apr 6, 2024, at 11:10 AM, Carsten Bormann <cabo@tzi.org> wrote:
>> 
>> Hi Laurence,
>> 
>> On 6. Apr 2024, at 19:47, lgl island-resort.com <lgl@island-resort.com> wrote:
>>> 
>>> 
>>>> On Apr 6, 2024, at 6:56 AM, Anders Rundgren <anders.rundgren.net@gmail.com> wrote:
>>>> 
>>>> Although I personally don't find the CBOR int/bignum arrangement ideal, this boat has (since long) already sailed and nobody died.
>>> 
>>> It looks to me that there is a new requirement in draft-ietf-cbor-cde-02 that isn’t in RFC 7049 (canonical CBOR) or RFC 8949 (Preferred Serialization and CDE). The requirement is that no value that can fit into an int64 or uint64 can be sent as a tag 3. That implies 65-bit negatives ints must be sent.
>> 
>> This is not a “new requirement” [1].
>> 
>> [1]: https://www.rfc-editor.org/rfc/rfc8949.html#section-3.4.3
>> 
>> Grüße, Carsten
>> 
> 
> _______________________________________________
> CBOR mailing list
> CBOR@ietf.org
> https://www.ietf.org/mailman/listinfo/cbor