Re: [Cbor] Decoding of 64-bit CBOR ints on 32-bit systems

Carsten Bormann <cabo@tzi.org> Sat, 27 April 2019 22:06 UTC

Return-Path: <cabo@tzi.org>
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 C14D01202B9 for <cbor@ietfa.amsl.com>; Sat, 27 Apr 2019 15:06:35 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -4.2
X-Spam-Level:
X-Spam-Status: No, score=-4.2 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gzV_4yLej1Ht for <cbor@ietfa.amsl.com>; Sat, 27 Apr 2019 15:06:33 -0700 (PDT)
Received: from smtp.uni-bremen.de (gabriel-vm-2.zfn.uni-bremen.de [134.102.50.17]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 389A71202B2 for <cbor@ietf.org>; Sat, 27 Apr 2019 15:06:33 -0700 (PDT)
Received: from [192.168.217.106] (p54A6CC75.dip0.t-ipconnect.de [84.166.204.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.uni-bremen.de (Postfix) with ESMTPSA id 44s4kv0xq0zyZD; Sun, 28 Apr 2019 00:06:31 +0200 (CEST)
Content-Type: text/plain; charset="utf-8"
Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\))
From: Carsten Bormann <cabo@tzi.org>
In-Reply-To: <7F3512DE-A3E2-41F1-A514-EC3F0BF2E3F3@felipegasper.com>
Date: Sun, 28 Apr 2019 00:06:30 +0200
Cc: cbor@ietf.org
X-Mao-Original-Outgoing-Id: 578095588.3287621-aaa741f7c1d92e76dc97ae73500ea59e
Content-Transfer-Encoding: quoted-printable
Message-Id: <6A0E6EDA-2337-4682-A753-7ACEBB3AB7BB@tzi.org>
References: <7F3512DE-A3E2-41F1-A514-EC3F0BF2E3F3@felipegasper.com>
To: Felipe Gasper <felipe@felipegasper.com>
X-Mailer: Apple Mail (2.3445.9.1)
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/EzyK7vSPFZ_ddtI2u8AyWM9Gdsk>
Subject: Re: [Cbor] Decoding of 64-bit CBOR ints on 32-bit systems
X-BeenThere: cbor@ietf.org
X-Mailman-Version: 2.1.29
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: Sat, 27 Apr 2019 22:06:36 -0000

Hi Felipe,

> On Apr 27, 2019, at 23:14, Felipe Gasper <felipe@felipegasper.com> wrote:
> 
> 	Is there either a custom or a standard that guides interpretation of 64-bit CBOR integers on 32-bit systems that don’t have 64-bit emulation?

How to interpret this question depends a bit on what you are trying to do.  Let me try to list the possibilities:

(1) I have an application protocol that makes use of integers that don’t fit into the 32-bit integers I have on my systems.

(2) I have an application protocol that doesn’t make use of such integers.  A CBOR encoder could still use a 64-bit form for such an integer (non-preferred encoding).

Orthogonal to this is the question whether you are employing a generic CBOR decoder or an application-specific one.

I think for (2) with a generic CBOR decoder, my recommendation would be to handle this in the generic CBOR decoder (e.g., by checking that the upper 32 bits are zero); similarly for an application specific CBOR decoder.  Alternatively, the application protocol could outright forbid 64-bit forms, just like it could forbid floating point numbers.

For (1), any application-specific CBOR decoder would then have to handle this case in a way that makes sense for the application.  A generic CBOR decoder could define its own 64-bit integer type (not necessarily with all the usual operations implemented), e.g. as a struct of two 32-bit unsigned integers.  Such a generic decoder would, of course, also work for (2); I’d probably still recommend that the decoder deliver integers where the upper half is zero as simple 32-bit integers.  An application of type (2) would handle any input that has those 64-bit structures as “unexpected” input.

Similar considerations apply for other data types not supported by the platform, e.g. 64-bit floating point values (or floating point values at all); it is maybe more obvious how to handle these.

After trying to handle your question in a general way, I think you can see what we would like to know about the specific circumstances to really answer this question.

Grüße, Carsten