<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE rfc SYSTEM "rfc2629-xhtml.ent">

<rfc number="8746" xmlns:xi="http://www.w3.org/2001/XInclude" consensus="true"
     ipr="trust200902" docName="draft-ietf-cbor-array-tags-08" category="std"
     obsoletes="" updates="" submissionType="IETF" xml:lang="en"
     tocInclude="true" sortRefs="true" symRefs="true" version="3"> 

  <front>
    <title abbrev="CBOR tags for typed arrays">Concise Binary Object
    Representation (CBOR) Tags for Typed Arrays</title>
    <seriesInfo name="RFC" value="8746"/>    
    <author initials="C." surname="Bormann" fullname="Carsten Bormann" role="editor">
      <organization>Universität Bremen TZI</organization>
      <address>
        <postal>
          <street>Postfach 330440</street>
          <city>Bremen</city>
          <code>D-28359</code>
          <country>Germany</country>
        </postal>
        <phone>+49-421-218-63921</phone>
        <email>cabo@tzi.org</email>
      </address>
    </author>
    <date month="February" year="2020"/>

<keyword>binary format</keyword>
<keyword>data interchange format</keyword>
<keyword>JSON</keyword>

    <abstract>
      <t>The Concise Binary Object Representation (CBOR), as defined in RFC
      7049, is a data format whose design goals include the possibility of
      extremely small code size, fairly small message size, and extensibility
      without the need for version negotiation.</t>
      <t>This document makes use of this extensibility to define a number of
      CBOR tags for typed arrays of numeric data, as well as additional
      tags for multi-dimensional and homogeneous arrays.  It is intended as
      the reference document for the IANA registration of the CBOR tags
      defined.</t>
    </abstract>
  </front>
  <middle>
    <section anchor="intro" numbered="true" toc="default">
      <name>Introduction</name>
      <t>The Concise Binary Object Representation (CBOR) <xref
      target="RFC7049" format="default"/> provides for the interchange of
      structured data without a requirement for a pre-agreed schema.  <xref
      target="RFC7049"/> defines a basic set of data types as well as a
      tagging mechanism that enables extending the set of data types supported
      via an IANA registry.</t>
      <t>Recently, a simple form of typed arrays of numeric data has received
      interest both in the Web graphics community <xref target="TypedArray"
      format="default"/> and in the JavaScript specification (see <eref
      target="https://www.ecma-international.org/ecma-262/10.0/index.html#sec-typedarray-objects">Section
      22.2</eref> of <xref target="ECMA-ES10" format="default"/>) as well as
      in corresponding implementations <xref target="ArrayBuffer"
      format="default"/>.</t>
      <t>Since these typed arrays may carry significant amounts of data, there
      is interest in interchanging them in CBOR without the need of lengthy
      conversion of each number in the array.  This can also save space
      overhead with encoding a type for each element of an array.</t>
      <t>This document defines a number of interrelated CBOR tags that cover
      these typed arrays, as well as additional tags for multi-dimensional and
      homogeneous arrays.  It is intended as the reference document for the
      IANA registration of the tags defined.</t>
      <t>Note that an application that generates CBOR with these tags has
      considerable freedom in choosing variants (e.g., with respect to
      endianness, embedded type (signed vs. unsigned), and number of bits per
      element) or whether a tag defined in this specification is used at all
      instead of more basic CBOR.  In contrast to representation variants of
      single CBOR numbers, there is no representation that could be identified
      as "preferred".  If deterministic encoding is desired in a CBOR-based
      protocol making use of these tags, the protocol has to define which of
      the encoding variants are used for each individual case.</t>

      <section anchor="terms" numbered="true" toc="default">
        <name>Terminology</name>


        <t>
    The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>",
    "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL
    NOT</bcp14>", "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>",
    "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>",
    "<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" in this document are
    to be interpreted as described in BCP&nbsp;14 <xref target="RFC2119"/>
    <xref target="RFC8174"/> when, and only when, they appear in all capitals,
    as shown here.
        </t>

        <t>The term "byte" is used in its now-customary sense as a synonym for
        "octet".  Where bit arithmetic is explained, this document uses
        familiar notation from the programming language C <xref target="C"
        format="default"/> (including C++14's 0bnnn binary literals <xref
        target="CPlusPlus" format="default"/>) with the exception of the
        operator "**", which stands for exponentiation.</t>
        <t>The term "array" is used in a general sense in this document unless
        further specified.  The term "classical CBOR array" describes an array
        represented with CBOR major type 4.  A "homogeneous array" is an array
        of elements that are all the same type (the term is neutral as to
        whether that is a representation type or an application data model
        type).</t>
        <t>The terms "big endian" and "little endian" are used to indicate a
        most significant byte first (MSB first) representation of integers and
        a least significant byte first (LSB first) representation,
        respectively.</t>
      </section>
    </section>

  <section anchor="typedarrays" numbered="true" toc="default">
      <name>Typed Arrays</name>
      <t>Typed arrays are homogeneous arrays of numbers, all of which are
      encoded in a single form of binary representation.  The concatenation of
      these representations is encoded as a single CBOR byte string (major
      type 2), enclosed by a single tag indicating the type and encoding of
      all the numbers represented in the byte string.</t>
      <section anchor="dataTypes" numbered="true" toc="default">
        <name>Types of Numbers</name>
        <t>Three classes of numbers are of interest: unsigned integers (uint),
        signed integers (two's complement, sint), and IEEE 754 binary floating
        point numbers (which are always signed).  For each of these classes,
        there are multiple representation lengths in active use:</t>
        <table anchor="lengths" align="center">
          <name>Length Values</name>
          <thead>
            <tr>
              <th align="left">Length ll</th>
              <th align="left">uint</th>
              <th align="left">sint</th>
              <th align="left">float</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td align="left">0</td>
              <td align="left">uint8</td>
              <td align="left">sint8</td>
              <td align="left">binary16</td>
            </tr>
            <tr>
              <td align="left">1</td>
              <td align="left">uint16</td>
              <td align="left">sint16</td>
              <td align="left">binary32</td>
            </tr>
            <tr>
              <td align="left">2</td>
              <td align="left">uint32</td>
              <td align="left">sint32</td>
              <td align="left">binary64</td>
            </tr>
            <tr>
              <td align="left">3</td>
              <td align="left">uint64</td>
              <td align="left">sint64</td>
              <td align="left">binary128</td>
            </tr>
          </tbody>
        </table>
        <t>Here, sintN stands for a signed integer of exactly N bits (for
        instance, sint16), and uintN stands for an unsigned integer of exactly
        N bits (for instance, uint32).  The name binaryN stands for the number
        form of the same name defined in IEEE 754 <xref target="IEEE754"
        format="default"/>.</t>
       

 <t>Since one objective of these tags is to be able to directly ship the
 ArrayBuffers underlying the Typed Arrays without re-encoding them, and these
 may be either in big-endian (network byte order) or in little-endian form, we
 need to define tags for both variants.</t>
        <t>In total, this leads to 24 variants.  In the tag, we need to
        express the choice between integer and floating point, the signedness
        (for integers), the endianness, and one of the four length values.</t>
        <t>In order to simplify implementation, a range of tags is being
        allocated that allows retrieving all this information from the bits of
        the tag: tag values from 64 to 87.
        </t>
        <t>The value is split up into 5 bit fields: 0b010, f, s, e, and ll as
        detailed in <xref target="fields" format="default"/>.</t>

        <table anchor="fields" align="center">
          <name>Bit Fields in the Low 8 Bits of the Tag</name>
          <thead>
            <tr>
              <th align="left">Field</th>
              <th align="left">Use</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td align="left">0b010</td>
              <td align="left">the constant bits 0, 1, 0</td>
            </tr>
            <tr>
              <td align="left">f</td>
              <td align="left">0 for integer, 1 for float</td>
            </tr>
            <tr>
              <td align="left">s</td>
              <td align="left">0 for float or unsigned integer, 1 for signed integer</td>
            </tr>
            <tr>
              <td align="left">e</td>
              <td align="left">0 for big endian, 1 for little endian</td>
            </tr>
            <tr>
              <td align="left">ll</td>
              <td align="left">A number for the length (<xref target="lengths" format="default"/>).</td>
            </tr>
          </tbody>
        </table>

        <t>The number of bytes in each array element can then be calculated by
        <tt>2**(f + ll)</tt> (or <tt>1 &lt;&lt; (f + ll)</tt> in a typical
        programming language).  (Notice that 0f and ll are the two least
        significant bits, respectively, of each 4-bit nibble in the byte.)</t>
        <t>In the CBOR representation, the total number of elements in the
        array is not expressed explicitly but is implied from the length of
        the byte string and the length of each representation.  It can be
        computed from the length, in bytes, of the byte string comprising the
        representation of the array by inverting the previous formula:
        <tt>bytelength &gt;&gt; (f + ll)</tt>.</t>
        <t>For the uint8/sint8 values, the endianness is redundant.  Only the
        tag for the big-endian variant is used and assigned as such.  The tag
        that would signify the little-endian variant of sint8 <bcp14>MUST
        NOT</bcp14> be used; its tag number is marked as reserved.  As a
        special case, the tag that would signify the little-endian variant of
        uint8 is instead assigned to signify that the numbers in the array are
        using clamped conversion from integers, as described in more detail in
        <eref
        target="http://www.ecma-international.org/ecma-262/6.0/#sec-touint8clamp">Section&nbsp;7.1.11</eref>
        of the ES10 JavaScript specification (<tt>ToUint8Clamp</tt>) <xref
        target="ECMA-ES10" format="default"/>; the assumption here is that a
        program-internal representation of this array after decoding would be
        marked this way for further processing providing "roundtripping" of
        JavaScript-typed arrays through CBOR.</t>
        <t>IEEE 754 binary floating numbers are always signed.  Therefore, for
        the float variants (<tt>f</tt> == 1), there is no need to distinguish
        between signed and unsigned variants; the <tt>s</tt> bit is always
        zero.  The tag numbers where <tt>s</tt> would be one (which would have
        tag values 88 to 95) remain free to use by other specifications.</t>
      </section>
    </section>
    <section anchor="additional-array-tags" numbered="true" toc="default">
      <name>Additional Array Tags</name>
      <t>This specification defines three additional array tags.  The
      Multi-dimensional Array tags can be combined with classical CBOR arrays
      as well as with Typed Arrays in order to build multi-dimensional arrays
      with constant numbers of elements in the sub-arrays.  The Homogeneous
      Array tag can be used as a signal by an application to identify a
      classical CBOR array as a homogeneous array, even when a Typed Array
      does not apply.</t>
      <section anchor="multi-dimensional-array" numbered="true" toc="default">
        <name>Multi-dimensional Array</name>
        <t>A multi-dimensional array is represented as a tagged array that
        contains two (one-dimensional) arrays.  The first array defines the
        dimensions of the multi-dimensional array (in the sequence of outer
        dimensions towards inner dimensions) while the second array represents
        the contents of the multi-dimensional array.  If the second array is
        itself tagged as a Typed Array, then the element type of the
        multi-dimensional array is known to be the same type as that of the
        Typed Array.</t>
        <t>Two tags are defined by this document: one for elements arranged in
        row-major order and another for column-major order <xref
        target="RowColMajor" format="default"/>.</t>
        <section anchor="row-major-order" numbered="true" toc="default">
          <name>Row-Major Order</name>
          <dl newline="false" spacing="normal">
            <dt>Tag:</dt>
            <dd>
  40</dd>
            <dt>Data Item:</dt>
            <dd>
  Array (major type 4) of two arrays: one array (major type 4) of dimensions,
  which are unsigned integers distinct from zero; and one array (any one of a
  CBOR array of major type 4, a Typed Array, or a Homogeneous Array) of
  elements.</dd>
          </dl>
          <t>Data in the second array consists of consecutive values where the
          last dimension is considered contiguous (row-major order).</t>
          <t><xref target="ex-multidim" format="default"/> shows a declaration
          of a two-dimensional array in the C language, a representation of
          that in CBOR using both a multi-dimensional array tag and a typed
          array tag.</t>
          <figure anchor="ex-multidim">
            <name>Multi-dimensional Array in C and CBOR</name>      
<sourcecode type="C">
uint16_t a[2][3] = {
  {2, 4, 8},   /* row 0 */
  {4, 16, 256},
};

&lt;Tag 40&gt; # multi-dimensional array tag
   82       # array(2)
     82      # array(2)
       02     # unsigned(2) 1st Dimension
       03     # unsigned(3) 2nd Dimension
     &lt;Tag 65&gt; # uint16 array
       4c     # byte string(12)
         0002 # unsigned(2)
         0004 # unsigned(4)
         0008 # unsigned(8)
         0004 # unsigned(4)
         0010 # unsigned(16)
         0100 # unsigned(256)
</sourcecode>  
          </figure>
          <t><xref target="ex-multidim1" format="default"/> shows the same
          two-dimensional array using the multi-dimensional array tag in
          conjunction with a basic CBOR array (which, with the small numbers
          chosen for the example, happens to be shorter).</t>
          <figure anchor="ex-multidim1">
            <name>Multi-dimensional Array Using Basic CBOR Array</name>
<sourcecode type="CBOR">
&lt;Tag 40&gt; # multi-dimensional array tag
   82       # array(2)
     82      # array(2)
       02     # unsigned(2) 1st Dimension
       03     # unsigned(3) 2nd Dimension
     86     # array(6)
       02      # unsigned(2)
       04      # unsigned(4)
       08      # unsigned(8)
       04      # unsigned(4)
       10      # unsigned(16)
       19 0100 # unsigned(256)
</sourcecode>

          </figure>
        </section>
        <section anchor="column-major-order" numbered="true" toc="default">
          <name>Column-Major Order</name>
          <t>The multi-dimensional arrays specified in the previous
          sub-subsection are in "row major" order, which is the preferred
          order for the purposes of this specification.  An analogous
          representation that uses "column major" order arrays is provided in
          this subsection under the tag 1040, as illustrated in <xref
          target="ex-multidim2" format="default"/>.</t>
          <dl newline="false" spacing="normal">
            <dt>Tag:</dt>
            <dd>
  1040</dd>
            <dt>Data Item:</dt>
            <dd>
  The same as tag 40, except the data in the second array consists of
  consecutive values where the first dimension is considered contiguous
  (column-major order).</dd>
          </dl>
          <figure anchor="ex-multidim2">
            <name>Multi-dimensional Array Using Basic CBOR Array, Column-Major Order</name>
<sourcecode type="CBOR">
&lt;Tag 1040&gt; # multi-dimensional array tag, column-major order
   82       # array(2)
     82      # array(2)
       02     # unsigned(2) 1st Dimension
       03     # unsigned(3) 2nd Dimension
     86     # array(6)
       02      # unsigned(2)
       04      # unsigned(4)
       04      # unsigned(4)
       10      # unsigned(16)
       08      # unsigned(8)
       19 0100 # unsigned(256)
</sourcecode>

          </figure>
        </section>
      </section>
      <section anchor="homogeneous-array" numbered="true" toc="default">
        <name>Homogeneous Array</name>
        <dl newline="false" spacing="normal">
          <dt>Tag:</dt>
          <dd>
  41</dd>
          <dt>Data Item:</dt>
          <dd>
  Array (major type 4)</dd>
        </dl>
        <t>This tag identifies the classical CBOR array (a one-dimensional
        array) tagged by it as a homogeneous array, that is, it has elements
        that are all of the same application model data type.  The element
        type of the array is therefore determined by the application model
        data type of the first array element.</t>
        <t>This can be used in application data models that apply specific
        semantics to homogeneous arrays.  Also, in certain cases,
        implementations in strongly typed languages may be able to create
        native homogeneous arrays of specific types instead of ordered lists
        while decoding.  Which CBOR data items constitute elements of the same
        application type is specific to the application.</t>
        <t><xref target="ex-homogeneous" format="default"/> shows an example
        for a homogeneous array of booleans in C++ <xref target="CPlusPlus"
        format="default"/> and CBOR.</t>
        <figure anchor="ex-homogeneous">
          <name>Homogeneous Array in C++ and CBOR</name>
<sourcecode type="C++">
bool boolArray[2] = { true, false };

&lt;Tag 41&gt;  # Homogeneous Array Tag
   82           #array(2)
      F5        # true
      F4        # false
</sourcecode>

        </figure>
        <t><xref target="ex-homogeneous1" format="default"/> extends the
        example with a more complex structure.</t>
        <figure anchor="ex-homogeneous1">
          <name>Homogeneous Array in C++ and CBOR</name>
<sourcecode type="C++">
typedef struct {
  bool active;
  int value;
} foo;
foo myArray[2] = { {true, 3}, {true, -4} };

&lt;Tag 41&gt;
    82  # array(2)
       82  #  array(2)
             F5  # true
             03  # 3
       82 # array(2)
             F5  # true
             23  # -4
</sourcecode>
        </figure>
      </section>
    </section>
    <section anchor="discussion" numbered="true" toc="default">
      <name>Discussion</name>
      <t>Support for both little- and big-endian representation may seem out
      of character with CBOR, which is otherwise fully big endian.  This
      support is in line with the intended use of the typed arrays and the
      objective not to require conversion of each array element.</t>
      <t>This specification allocates a sizable chunk out of the single-byte
      tag space.  This use of code point space is justified by the wide use of
      typed arrays in data interchange.</t>
      <t>Providing a column-major order variant of the multi-dimensional array
      may seem superfluous to some and useful to others.  It is cheap to
      define the additional tag so that it is available when actually needed.
      Allocating it out of a different number space makes the preference for
      row-major evident.</t>
      <t>Applying a Homogeneous Array tag to a Typed Array would usually be
      redundant and is therefore not provided by the present
      specification.</t>
      <t/>
    </section>
    <section anchor="cddl-typenames" numbered="true" toc="default">
      <name>CDDL Typenames</name>
      <t>For use with CDDL <xref target="RFC8610" format="default"/>, the
      typenames defined in <xref target="tag-cddl" format="default"/> are
      recommended:</t>
      <figure anchor="tag-cddl">
        <name>Recommended Typenames for CDDL</name>
<sourcecode type="CDDL">
ta-uint8 = #6.64(bstr)
ta-uint16be = #6.65(bstr)
ta-uint32be = #6.66(bstr)
ta-uint64be = #6.67(bstr)
ta-uint8-clamped = #6.68(bstr)
ta-uint16le = #6.69(bstr)
ta-uint32le = #6.70(bstr)
ta-uint64le = #6.71(bstr)
ta-sint8 = #6.72(bstr)
ta-sint16be = #6.73(bstr)
ta-sint32be = #6.74(bstr)
ta-sint64be = #6.75(bstr)
; reserved: #6.76(bstr)
ta-sint16le = #6.77(bstr)
ta-sint32le = #6.78(bstr)
ta-sint64le = #6.79(bstr)
ta-float16be = #6.80(bstr)
ta-float32be = #6.81(bstr)
ta-float64be = #6.82(bstr)
ta-float128be = #6.83(bstr)
ta-float16le = #6.84(bstr)
ta-float32le = #6.85(bstr)
ta-float64le = #6.86(bstr)
ta-float128le = #6.87(bstr)
homogeneous&lt;array&gt; = #6.41(array)
multi-dim&lt;dim, array&gt; = #6.40([dim, array])
multi-dim-column-major&lt;dim, array&gt; = #6.1040([dim, array])
</sourcecode>

      </figure>
      <t/>
    </section>
    <section anchor="iana-considerations" numbered="true" toc="default">
      <name>IANA Considerations</name>


      <t>IANA has allocated the tags in <xref target="tab-tag-values"
      format="default"/> using this document as the specification reference.
      (The reserved value is for a future revision of typed array tags.)</t>
      <t>The allocations were assigned from the "specification required" space
      (24..255) with the exception of 1040, which was assigned from the "first come
      first served" space (256..).</t>
      <table anchor="tab-tag-values" align="center">
        <name>Values for Tags</name>
        <thead>
          <tr>
            <th align="right">Tag</th>
            <th align="left">Data Item</th>
            <th align="left">Semantics</th>
          </tr>
        </thead>
        <tbody>
    
         <tr>
            <td align="right">40</td>
            <td align="left">array of two arrays*</td>
            <td align="left">Multi-dimensional Array, row-major order</td>
          </tr>
          <tr>
            <td align="right">41</td>
            <td align="left">array</td>
            <td align="left">Homogeneous Array</td>
          </tr>
         <tr>
            <td align="right">64</td>
            <td align="left">byte string</td>
            <td align="left">uint8 Typed Array</td>
          </tr>
          <tr>
            <td align="right">65</td>
            <td align="left">byte string</td>
            <td align="left">uint16, big endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">66</td>
            <td align="left">byte string</td>
            <td align="left">uint32, big endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">67</td>
            <td align="left">byte string</td>
            <td align="left">uint64, big endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">68</td>
            <td align="left">byte string</td>
            <td align="left">uint8 Typed Array, clamped arithmetic</td>
          </tr>
          <tr>
            <td align="right">69</td>
            <td align="left">byte string</td>
            <td align="left">uint16, little endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">70</td>
            <td align="left">byte string</td>
            <td align="left">uint32, little endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">71</td>
            <td align="left">byte string</td>
            <td align="left">uint64, little endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">72</td>
            <td align="left">byte string</td>
            <td align="left">sint8 Typed Array</td>
          </tr>
          <tr>
            <td align="right">73</td>
            <td align="left">byte string</td>
            <td align="left">sint16, big endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">74</td>
            <td align="left">byte string</td>
            <td align="left">sint32, big endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">75</td>
            <td align="left">byte string</td>
            <td align="left">sint64, big endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">76</td>
            <td align="left">byte string</td>
            <td align="left">(reserved)</td>
          </tr>
          <tr>
            <td align="right">77</td>
            <td align="left">byte string</td>
            <td align="left">sint16, little endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">78</td>
            <td align="left">byte string</td>
            <td align="left">sint32, little endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">79</td>
            <td align="left">byte string</td>
            <td align="left">sint64, little endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">80</td>
            <td align="left">byte string</td>
            <td align="left">IEEE 754 binary16, big endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">81</td>
            <td align="left">byte string</td>
            <td align="left">IEEE 754 binary32, big endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">82</td>
            <td align="left">byte string</td>
            <td align="left">IEEE 754 binary64, big endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">83</td>
            <td align="left">byte string</td>
            <td align="left">IEEE 754 binary128, big endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">84</td>
            <td align="left">byte string</td>
            <td align="left">IEEE 754 binary16, little endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">85</td>
            <td align="left">byte string</td>
            <td align="left">IEEE 754 binary32, little endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">86</td>
            <td align="left">byte string</td>
            <td align="left">IEEE 754 binary64, little endian, Typed Array</td>
          </tr>
          <tr>
            <td align="right">87</td>
            <td align="left">byte string</td>
            <td align="left">IEEE 754 binary128, little endian, Typed Array</td>
          </tr>    
          <tr>
            <td align="right">1040</td>
            <td align="left">array of two arrays*</td>
            <td align="left">Multi-dimensional Array, column-major order</td>
          </tr>

        </tbody>
      </table>

<t>*40 or 1040 data item: The second element of the outer array in the data
item is a native CBOR array (major type 4) or Typed Array (one of tag
64..87)</t>


    </section>
    <section anchor="security-considerations" numbered="true" toc="default">
      <name>Security Considerations</name>
      <t>The security considerations of <xref target="RFC7049"/> apply;
      special attention is drawn to the second paragraph of <xref
      target="RFC7049" sectionFormat="of" section="8"/>.</t>
      <t>The tag for homogeneous arrays makes a promise about its tagged data
      item, which a maliciously constructed CBOR input can then choose to
      ignore.  As always, the decoder therefore has to ensure that it is not
      driven into an undefined state by array elements that do not fulfill the
      promise, and that it does continue to fulfill its API contract in this
      case as well.</t>
      <t>As with all formats that are used for data interchange, an attacker
      may have control over the shape of the data delivered as input to the
      application, which therefore needs to validate that shape before it
      makes it the basis of its further processing.  One unique aspect that
      typed arrays add to this is that an attacker might substitute a
      Uint8ClampedArray for where the application expects a Uint8Array, or
      vice versa, potentially leading to very different (and unexpected)
      processing semantics of the in-memory data structures constructed.
      Applications that could be affected by this will therefore need to be
      careful about making this distinction in their input validation.</t>
      <t/>
    </section>
  </middle>
  <back>
    <references>
      <name>References</name>
      <references>
        <name>Normative References</name>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7049.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8610.xml"/>

        <reference anchor="IEEE754" target ="https://ieeexplore.ieee.org/document/8766229">
          <front>
            <title>IEEE Standard for Floating-Point Arithmetic</title>
            <author>
              <organization>IEEE</organization>
            </author>
            <date/>
          </front>
<seriesInfo name="IEEE" value="754-2019"/>
<seriesInfo name="DOI" value="10.1109/IEEESTD.2019.8766229"/>
        </reference>


        <reference anchor="ECMA-ES10"
   target="https://www.ecma-international.org/ecma-262/10.0/index.html">
          <front>
            <title>ECMAScript 2019 Language Specification</title>
            <author>
              <organization>ECMA International
      </organization>
            </author>
            <date year="2019" month="June"/>
          </front>
            <refcontent>Standard ECMA-262 10th Edition</refcontent>
        </reference>

        <reference anchor="C">
          <front>
            <title>Information technology - Programming languages - C</title>
            <seriesInfo name="ISO/IEC" value="9899:2018, Fourth Edition"/>
            <author>
              <organization>International Organization for Standardization
      </organization>
            </author>
            <date month="June" year="2018"/>
          </front>
        </reference>

        <reference anchor="CPlusPlus">
          <front>
            <title>Programming languages - C++</title>
            <seriesInfo name="ISO/IEC" value="14882:2017, Fifth Edition"/>
            <author>
              <organization>International Organization for Standardization
      </organization>
            </author>
            <date month="December" year="2017"/>
          </front>
        </reference>

        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
        <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>

      </references>

      <references>
        <name>Informative References</name>

        <reference anchor="TypedArray" target="https://web.archive.org/web/20110207024413/http://www.khronos.org/registry/typedarray/specs/latest/">
          <front>
            <title>Typed Array Specification</title>
            <author initials="V." surname="Vukicevic" fullname="Vladimir Vukicevic">
              <organization>Mozilla Corporation</organization>
            </author>
            <author initials="K." surname="Russell" fullname="Kenneth Russell">
              <organization>Google, Inc.</organization>
            </author>
            <date year="2011" month="February"/>
          </front>
        </reference>

        <reference anchor="ArrayBuffer" target="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays">
          <front>
            <title>JavaScript typed arrays</title>
            <author>
              <organization>Mozilla Developer Network</organization>
            </author>
            <date month="June" year="2010"/>
          </front>
        </reference>

        <reference anchor="RowColMajor" target="https://en.wikipedia.org/w/index.php?title=Row-_and_column-major_order&amp;oldid=917905325">
          <front>
            <title>Row- and column-major order</title>
            <author>
              <organization>Wikipedia</organization>
            </author>
            <date year="2019" month="September"/>
          </front>
        </reference>

      </references>
    </references>

    <section numbered="false" anchor="acknowledgements" toc="default">
      <name>Acknowledgements</name>
      <t><contact fullname="Jim Schaad"/> provided helpful comments and reminded us that
      column-major order still is in use.  <contact fullname="Jeffrey Yaskin"/> helped improve the
      definition of homogeneous arrays.  IANA helped correct an error in a
      previous draft version.  <contact fullname="Francesca Palombini"/> acted as Shepherd, and
      <contact fullname="Alexey Melnikov"/> as responsible Area Director.
      <contact fullname="Elwyn Davies"/> as Gen-ART
      reviewer and IESG members <contact fullname="Martin Vigoureux"/>,
      <contact fullname="Adam Roach"/>, <contact fullname="Roman
      Danyliw"/>,
      and <contact fullname="Benjamin Kaduk"/> helped in finding further improvements to the text;
      thanks also to the other reviewers.</t>

    </section>

    <section numbered="false" anchor="contributors" toc="default">
      <name>Contributors</name> <t>The initial draft version of this
      specification was written by <contact fullname="Johnathan Roatch"/> &lt;roatch@gmail.com&gt;.
      Many thanks for getting this ball rolling.</t>
      <t><contact fullname="Glenn Engel"/> suggested the tags for multi-dimensional arrays and
      homogeneous arrays.</t>
    </section>

  </back>

</rfc>
