Re: [Cbor] Question about CBOR padding

Matt Vollrath <matt@endpoint.com> Wed, 07 November 2018 17:06 UTC

Return-Path: <matt@endpoint.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 B6DEE12D4F1 for <cbor@ietfa.amsl.com>; Wed, 7 Nov 2018 09:06:45 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2
X-Spam-Level:
X-Spam-Status: No, score=-2 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=endpoint.com
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 sJOxEkPevCvu for <cbor@ietfa.amsl.com>; Wed, 7 Nov 2018 09:06:44 -0800 (PST)
Received: from mail.endcrypt.com (mail.endcrypt.com [IPv6:2607:f0d0:1301:23::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 7AFF6129C6A for <cbor@ietf.org>; Wed, 7 Nov 2018 09:06:44 -0800 (PST)
Received: from [192.168.1.8] (96-33-3-51.dhcp.jcsn.tn.charter.com [96.33.3.51]) (using TLSv1.2 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mail.endcrypt.com (Postfix) with ESMTPSA id BE99B803B4 for <cbor@ietf.org>; Wed, 7 Nov 2018 17:06:43 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=endpoint.com; s=mail; t=1541610403; bh=GwGIT6xc716d9FpQReJ+UpYi7HoDyySUmW9Bv810xBc=; h=Subject:To:References:From:Date:In-Reply-To:From; b=aZajv90hW6XPMbe2U5cbeeFgoLydrRB7aOyOrS2tVjN/gxJpNcsqV30jmlO7fnDq2 tw1uRlVVa7Wh8IDqrXsh2DhwV98oSHiFzwdkuGjnkU+00PBaTCjRwHjaPjUu+PGm8G Oa22VXY2cinNKClSGJyDUEVwrer1pf/y3mgeH9Iku0nThpLizd28e0RRjngvSmgjDy aB3eN4z7TDuLokyANCLuEaBOFDYShKAqsd4i4YKZkBn6ed0BVblhfIWjJdGBBuEM/g 7/zzJGUxGPAB00HryfmtCNqxTIYklbZdXMl3KqePp4SiXADhuJjy/1qBfE6tDSHHka vekS45/Deu32Q==
To: cbor@ietf.org
References: <mailman.3695.1541565786.6265.cbor@ietf.org>
From: Matt Vollrath <matt@endpoint.com>
Message-ID: <ade142b3-cc6c-2ede-7d94-77de01bacc46@endpoint.com>
Date: Wed, 07 Nov 2018 12:06:42 -0500
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1
MIME-Version: 1.0
In-Reply-To: <mailman.3695.1541565786.6265.cbor@ietf.org>
Content-Type: multipart/alternative; boundary="------------A26EF5DA3CBBE6B8572EC387"
Content-Language: en-US
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/1MudDri0Cp38bztqSJXJnczJr-0>
Subject: Re: [Cbor] Question about CBOR padding
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: Wed, 07 Nov 2018 17:06:46 -0000

Michael Richardson <mcr+ietf@sandelman.ca>; wrote:
> Thiago Macieira  <thiago.macieira@intel.com>; wrote:
>     > CBOR has no need for  padding and it does not have any byte sequence that can
>     > fill in for padding.
> 
> True.
> 
> You could pad with a sized or  series of indefinite length array that ended
> with no items.  I think it's best  to just read the first "element", and
> ignore the rest though.

I agree with reading the first element and ignoring the rest.

My experience with JavaScript CBOR libraries has not been kind, though.  
Every library I've tested ('cbor', 'cbor-js', 'fast-cbor') fails when 
there are any trailing bytes, even when using a method that should only 
return the first element.  This behavior appears to be in line with the 
spec, which says that decoders can handle anomalous data basically 
however they like.

The spec suggests that any attempt at padding is unsupported in 3.2:

 > CBOR data is well-formed if it uses
 > the initial bytes, as well as the byte strings and/or data items that
 > are implied by their values, in the manner defined by CBOR, and no
 > extraneous data follows (Appendix C).

So it seems like if somebody has a good reason to stuff CBOR data into 
PNG pixels, they'll need to separately convey the number of bytes to 
chop off of the end or use a decoder implementation that specifically 
supports the case.  I can see how this makes the decoder implementation 
requirements leaner.

The Python 'cbor' library gets a gold star for not being broken when 
there are trailing bytes.

Thanks
mv