home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1997 December / Internet_Info_CD-ROM_Walnut_Creek_December_1997.iso / drafts / draft_s_z / draft-yergeau-utf8-rev-01.txt < prev    next >
Text File  |  1997-09-11  |  20KB  |  504 lines

  1.  
  2.  
  3. Network Working Group                                       F. Yergeau
  4. Internet Draft                                       Alis Technologies
  5. <draft-yergeau-utf8-rev-01.txt>                      10 September 1997
  6. Expires 15 March 1998
  7.  
  8. [Will obsolete RFC 2044]
  9.  
  10.               UTF-8, a transformation format of ISO 10646
  11.  
  12.  
  13. Status of this Memo
  14.  
  15.    This document is an Internet-Draft.  Internet-Drafts are working doc-
  16.    uments of the Internet Engineering Task Force (IETF), its areas, and
  17.    its working groups. Note that other groups may also distribute work-
  18.    ing documents as Internet-Drafts.
  19.  
  20.    Internet-Drafts are draft documents valid for a maximum of six
  21.    months.  Internet-Drafts may be updated, replaced, or obsoleted by
  22.    other documents at any time.  It is not appropriate to use Internet-
  23.    Drafts as reference material or to cite them other than as a "working
  24.    draft" or "work in progress".
  25.  
  26.    To learn the current status of any Internet-Draft, please check the
  27.    1id-abstracts.txt listing contained in the Internet-Drafts Shadow
  28.    Directories on ds.internic.net (US East Coast), nic.nordu.net
  29.    (Europe), ftp.isi.edu (US West Coast), or munnari.oz.au (Pacific
  30.    Rim).
  31.  
  32.    Distribution of this document is unlimited.
  33.  
  34. Abstract
  35.  
  36.    ISO/IEC 10646-1 defines a multi-octet character set called the Uni-
  37.    versal Character Set (UCS) which encompasses most of the world's
  38.    writing systems. Multi-octet characters, however, are not compatible
  39.    with many current applications and protocols, and this has led to the
  40.    development of a few so-called UCS transformation formats (UTF), each
  41.    with different characteristics.  UTF-8, the object of this memo, has
  42.    the characteristic of preserving the full US-ASCII range, providing
  43.    compatibility with file systems, parsers and other software that rely
  44.    on US-ASCII values but are transparent to other values. This memo
  45.    updates and replaces RFC 2044, in particular addressing the question
  46.    of versions of the relevant standards.
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.                           Expires 15 March 1998         [Page 1]
  55.  
  56. Internet Draft                    UTF-8                10 September 1998
  57.  
  58.  
  59. 1.  Introduction
  60.  
  61.    ISO/IEC 10646-1 [ISO-10646] defines a multi-octet character set
  62.    called the Universal Character Set (UCS), which encompasses most of
  63.    the world's writing systems.  Two multi-octet encodings are defined,
  64.    a four-octet per character encoding called UCS-4 and a two-octet per
  65.    character encoding called UCS-2, able to address only the first 64K
  66.    characters of the UCS (the Basic Multilingual Plane, BMP), outside of
  67.    which there are currently no assignments.
  68.  
  69.    It is noteworthy that the same set of characters is defined by the
  70.    Unicode standard [UNICODE], which further defines additional charac-
  71.    ter properties and other application details of great interest to
  72.    implementors, but does not have the UCS-4 encoding.  Up to the pre-
  73.    sent time, changes in Unicode and amendments to ISO/IEC 10646 have
  74.    tracked each other, so that the character repertoires and code point
  75.    assignments have remained in sync.  The relevant standardization com-
  76.    mittees have committed to maintain this very useful synchronism.
  77.  
  78.    The UCS-2 and UCS-4 encodings, however, are hard to use in many cur-
  79.    rent applications and protocols that assume 8 or even 7 bit charac-
  80.    ters.  Even newer systems able to deal with 16 bit characters cannot
  81.    process UCS-4 data. This situation has led to the development of so-
  82.    called UCS transformation formats (UTF), each with different charac-
  83.    teristics.
  84.  
  85.    UTF-1 has only historical interest, having been removed from ISO/IEC
  86.    10646.  UTF-7 has the quality of encoding the full BMP repertoire
  87.    using only octets with the high-order bit clear (7 bit US-ASCII 
  88.    values, [US-ASCII]), and is thus deemed a mail-safe encoding
  89.    ([RFC2152]).  UTF-8, the object of this memo, uses all bits of an
  90.    octet, but has the quality of preserving the full US-ASCII range: 
  91.    US-ASCII characters are encoded in one octet having the normal 
  92.    US-ASCII value, and any octet with such a value can only stand for 
  93.    an US-ASCII character, and nothing else.
  94.  
  95.    UTF-16 is a scheme for transforming a subset of the UCS-4 repertoire
  96.    into pairs of UCS-2 values from a reserved range.  UTF-16 impacts
  97.    UTF-8 in that UCS-2 values from the reserved range must be treated
  98.    specially in the UTF-8 transformation.
  99.  
  100.    UTF-8 encodes UCS-2 or UCS-4 characters as a varying number of
  101.    octets, where the number of octets, and the value of each, depend on
  102.    the integer value assigned to the character in ISO/IEC 10646.  This
  103.    transformation format has the following characteristics (all values
  104.    are in hexadecimal):
  105.  
  106.  
  107.  
  108.  
  109.  
  110.                           Expires 15 March 1998         [Page 2]
  111.  
  112. Internet Draft                    UTF-8                10 September 1998
  113.  
  114.  
  115.    -  Character values from 0000 0000 to 0000 007F (US-ASCII repertoire)
  116.       correspond to octets 00 to 7F (7 bit US-ASCII values). A direct
  117.       consequence is that a plain ASCII string is also a valid UTF-8
  118.       string.
  119.  
  120.    -  US-ASCII values do not appear otherwise in a UTF-8 encoded charac-
  121.       ter stream.  This provides compatibility with file systems or
  122.       other software (e.g. the printf() function in C libraries) that
  123.       parse based on US-ASCII values but are transparent to other 
  124.       values.
  125.  
  126.    -  Round-trip conversion is easy between UTF-8 and either of UCS-4,
  127.       UCS-2.
  128.  
  129.    -  The first octet of a multi-octet sequence indicates the number of
  130.       octets in the sequence.
  131.  
  132.    -  The octet values FE and FF never appear.
  133.  
  134.    -  Character boundaries are easily found from anywhere in an octet
  135.       stream.
  136.  
  137.    -  The lexicographic sorting order of UCS-4 strings is preserved.  Of
  138.       course this is of limited interest since the sort order is not
  139.       culturally valid in either case.
  140.  
  141.    -  The Boyer-Moore fast search algorithm can be used with UTF-8 data.
  142.  
  143.    -  UTF-8 strings can be fairly reliably recognized as such by a sim-
  144.       ple algorithm, i.e. the probability that a string of characters in
  145.       any other encoding appears as valid UTF-8 is low, diminishing with
  146.       increasing string length.
  147.  
  148.    UTF-8 was originally a project of the X/Open Joint Internationaliza-
  149.    tion Group XOJIG with the objective to specify a File System Safe UCS
  150.    Transformation Format [FSS-UTF] that is compatible with UNIX systems,
  151.    supporting multilingual text in a single encoding.  The original
  152.    authors were Gary Miller, Greger Leijonhufvud and John Entenmann.
  153.    Later, Ken Thompson and Rob Pike did significant work for the formal
  154.    UTF-8.
  155.  
  156.    A description can also be found in Unicode Technical Report #4 and in
  157.    the Unicode Standard, version 2.0 [UNICODE].  The definitive refer-
  158.    ence, including provisions for UTF-16 data within UTF-8, is Annex R
  159.    of ISO/IEC 10646-1 [ISO-10646].
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.                           Expires 15 March 1998         [Page 3]
  167.  
  168. Internet Draft                    UTF-8                10 September 1998
  169.  
  170.  
  171. 2.  UTF-8 definition
  172.  
  173.    In UTF-8, characters are encoded using sequences of 1 to 6 octets.
  174.    The only octet of a "sequence" of one has the higher-order bit set to
  175.    0, the remaining 7 bits being used to encode the character value. In
  176.    a sequence of n octets, n>1, the initial octet has the n higher-order
  177.    bits set to 1, followed by a bit set to 0.  The remaining bit(s) of
  178.    that octet contain bits from the value of the character to be
  179.    encoded.  The following octet(s) all have the higher-order bit set to
  180.    1 and the following bit set to 0, leaving 6 bits in each to contain
  181.    bits from the character to be encoded.
  182.  
  183.    The table below summarizes the format of these different octet types.
  184.    The letter x indicates bits available for encoding bits of the UCS-4
  185.    character value.
  186.  
  187.    UCS-4 range (hex.)           UTF-8 octet sequence (binary)
  188.    0000 0000-0000 007F   0xxxxxxx
  189.    0000 0080-0000 07FF   110xxxxx 10xxxxxx
  190.    0000 0800-0000 FFFF   1110xxxx 10xxxxxx 10xxxxxx
  191.  
  192.    0001 0000-001F FFFF   11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  193.    0020 0000-03FF FFFF   111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
  194.    0400 0000-7FFF FFFF   1111110x 10xxxxxx ... 10xxxxxx
  195.  
  196.  
  197.    Encoding from UCS-4 to UTF-8 proceeds as follows:
  198.  
  199.    1) Determine the number of octets required from the character value
  200.       and the first column of the table above.  It is important to note
  201.       that the rows of the table are mutually exclusive, i.e. there is
  202.       only one valid way to encode a given UCS-4 character.
  203.  
  204.    2) Prepare the high-order bits of the octets as per the second column
  205.       of the table.
  206.  
  207.    3) Fill in the bits marked x from the bits of the character value,
  208.       starting from the lower-order bits of the character value and
  209.       putting them first in the last octet of the sequence, then the
  210.       next to last, etc. until all x bits are filled in.
  211.  
  212.       The algorithm for encoding UCS-2 (or Unicode) to UTF-8 can be
  213.       obtained from the above, in principle, by simply extending each
  214.       UCS-2 character with two zero-valued octets.  However, pairs of
  215.       UCS-2 values between D800 and DFFF (surrogate pairs in Unicode
  216.       parlance), being actually UCS-4 characters transformed through
  217.       UTF-16, need special treatment: the UTF-16 transformation MUST be
  218.       undone, yielding a UCS-4 character that is then transformed as
  219.  
  220.  
  221.  
  222.                           Expires 15 March 1998         [Page 4]
  223.  
  224. Internet Draft                    UTF-8                10 September 1998
  225.  
  226.  
  227.       above.
  228.  
  229.       Decoding from UTF-8 to UCS-4 proceeds as follows:
  230.  
  231.    1) Initialize the 4 octets of the UCS-4 character with all bits set
  232.       to 0.
  233.  
  234.    2) Determine which bits encode the character value from the number of
  235.       octets in the sequence and the second column of the table above
  236.       (the bits marked x).
  237.  
  238.    3) Distribute the bits from the sequence to the UCS-4 character,
  239.       first the lower-order bits from the last octet of the sequence and
  240.       proceeding to the left until no x bits are left.
  241.  
  242.       If the UTF-8 sequence is no more than three octets long, decoding
  243.       can proceed directly to UCS-2.
  244.  
  245.         NOTE -- actual implementations of the decoding algorithm
  246.         above should protect against decoding invalid sequences.
  247.         For instance, a naive implementation may (wrongly) decode
  248.         the invalid UTF-8 sequence C0 80 into the character U+0000,
  249.         which may have security consequences and/or cause other
  250.         problems.  See the Security Considerations section below.
  251.  
  252.    A more detailed algorithm and formulae can be found in [FSS_UTF],
  253.    [UNICODE] or Annex R to [ISO-10646].
  254.  
  255. 3.  Versions of the standards
  256.  
  257.    ISO/IEC 10646 is updated from time to time by published amendments;
  258.    similarly, different versions of the Unicode standard exist: 1.0, 1.1
  259.    and 2.0 as of this writing.  Each new version obsoletes and replaces
  260.    the previous one, but implementations, and more significantly data,
  261.    are not updated instantly.
  262.  
  263.    In general, the changes amount to adding new characters, which does
  264.    not pose particular problems with old data.  Amendment 5 to ISO/IEC
  265.    10646, however, has moved and expanded the Korean Hangul block,
  266.    thereby making any previous data containing Hangul characters invalid
  267.    under the new version.  Unicode 2.0 has the same difference from Uni-
  268.    code 1.1. The official justification for allowing such an incompati-
  269.    ble change was that no implementations and no data containing Hangul
  270.    existed, a statement that is likely to be true but remains unprov-
  271.    able.  The incident has been dubbed the "Korean mess", and the rele-
  272.    vant committees have pledged to never, ever again make such an incom-
  273.    patible change.
  274.  
  275.  
  276.  
  277.  
  278.                           Expires 15 March 1998         [Page 5]
  279.  
  280. Internet Draft                    UTF-8                10 September 1998
  281.  
  282.  
  283.    New versions, and in particular any incompatible changes, have conse-
  284.    quences regarding MIME character encoding labels, to be discussed in
  285.    section 5.
  286.  
  287. 4.  Examples
  288.  
  289.    The UCS-2 sequence "A<NOT IDENTICAL TO><ALPHA>." (0041, 2262, 0391,
  290.    002E) may be encoded in UTF-8 as follows:
  291.  
  292.    41 E2 89 A2 CE 91 2E
  293.  
  294.    The UCS-2 sequence representing the Hangul characters for the Korean
  295.    word "hangugo" (D55C, AD6D, C5B4) may be encoded as follows:
  296.  
  297.    ED 95 9C EA B5 AD EC 96 B4
  298.  
  299.    The UCS-2 sequence representing the Han characters for the Japanese
  300.    word "nihongo" (65E5, 672C, 8A9E) may be encoded as follows:
  301.  
  302.    E6 97 A5 E6 9C AC E8 AA 9E
  303.  
  304.  
  305. 5.  MIME registration
  306.  
  307.    This memo is meant to serve as the basis for registration of a MIME
  308.    character set parameter (charset) [CHARSET-REG].  The proposed
  309.    charset parameter value is "UTF-8".  This string labels media types
  310.    containing text consisting of characters from the repertoire of
  311.    ISO/IEC 10646 including all amendments at least up to amendment 5
  312.    (Korean block), encoded to a sequence of octets using the encoding
  313.    scheme outlined above.  UTF-8 is suitable for use in MIME content
  314.    types under the "text" top-level type.
  315.  
  316.    It is noteworthy that the label "UTF-8" does not contain a version
  317.    identification, referring generically to ISO/IEC 10646.  This is
  318.    intentional, the rationale being as follows:
  319.  
  320.    A MIME charset label is designed to give just the information needed
  321.    to interpret a sequence of bytes received on the wire into a sequence
  322.    of characters, nothing more (see RFC 2045, section 2.2, in [MIME]).
  323.    As long as a character set standard does not change incompatibly,
  324.    version numbers serve no purpose, because one gains nothing by learn-
  325.    ing from the tag that newly assigned characters may be received that
  326.    one doesn't know about.  The tag itself doesn't teach anything about
  327.    the new characters, which are going to be received anyway.
  328.  
  329.    Hence, as long as the standards evolve compatibly, the apparent
  330.    advantage of having labels that identify the versions is only that,
  331.  
  332.  
  333.  
  334.                           Expires 15 March 1998         [Page 6]
  335.  
  336. Internet Draft                    UTF-8                10 September 1998
  337.  
  338.  
  339.    apparent.  But there is a disadvantage to such version-dependent
  340.    labels: when an older application receives data accompanied by a
  341.    newer, unknown label, it may fail to recognize the label and be com-
  342.    pletely unable to deal with the data, whereas a generic, known label
  343.    would have triggered mostly correct processing of the data, which may
  344.    well not contain any new characters.
  345.  
  346.    Now the "Korean mess" (ISO/IEC 10646 amendment 5) is an incompatible
  347.    change, in principle contradicting the appropriateness of a version-
  348.    independent MIME charset label as described above.  But the compati-
  349.    bility problem can only appear with data containing Korean Hangul
  350.    characters encoded according to Unicode 1.1 (or equivalently ISO/IEC
  351.    10646 before amendment 5), and there is arguably no such data to
  352.    worry about, this being the very reason the incompatible change was
  353.    deemed acceptable.
  354.  
  355.    In practice, then, a version-independent label is warranted, provided
  356.    the label is understood to refer to all versions after Amendment 5,
  357.    and provided no incompatible change actually occurs.  Should incom-
  358.    patible changes occur in a later version of ISO/IEC 10646, the MIME
  359.    charset label defined here will stay aligned with the previous ver-
  360.    sion until and unless the IETF specifically decides otherwise.
  361.  
  362.    It is also proposed to register the charset parameter value 
  363.    "UNICODE-1-1-UTF-8", for the exclusive purpose of labelling text 
  364.    data containing Hangul syllables encoded to UTF-8 without taking into
  365.    account Amendment 5 of ISO/IEC 10646 (i.e. using the pre-amendment 5
  366.    code point assignments).  Any other UTF-8 data SHOULD NOT use this
  367.    label, in particular data not containing any Hangul syllables, and it
  368.    is felt important to strongly recommend against creating any new
  369.    Hangul-containing data without taking Amendment 5 of ISO/IEC 10646
  370.    into account.
  371.  
  372. 6.  Security Considerations
  373.  
  374.    Implementors of UTF-8 need to consider the security aspects of how
  375.    they handle illegal UTF-8 sequences.  It is conceivable that in some
  376.    circumstances an attacker would be able to exploit an incautious
  377.    UTF-8 parser by sending it an octet sequence that is not permitted by
  378.    the UTF-8 syntax.
  379.  
  380.    A particularly subtle form of this attack could be carried out
  381.    against a parser which performs security-critical validity checks
  382.    against the UTF-8 encoded form of its input, but interprets certain
  383.    illegal octet sequences as characters.  For example, a parser might
  384.    prohibit the NUL character when encoded as the single-octet sequence
  385.    00, but allow the illegal two-octet sequence C0 80 and interpret it
  386.    as a NUL character.  Another example might be a parser which
  387.  
  388.  
  389.  
  390.                           Expires 15 March 1998         [Page 7]
  391.  
  392. Internet Draft                    UTF-8                10 September 1998
  393.  
  394.  
  395.    prohibits the octet sequence 2F 2E 2E 2F ("/../"), yet permits the
  396.    illegal octet sequence 2F C0 AE 2E 2F.
  397.  
  398. Acknowledgments
  399.  
  400.    The following have participated in the drafting and discussion of
  401.    this memo:
  402.  
  403.    James E. Agenbroad    Andries Brouwer
  404.    Martin J. Dⁿrst       Ned Freed
  405.    David Goldsmith       Edwin F. Hart
  406.    Kent Karlsson         Markus Kuhn
  407.    Michael Kung          Alain LaBontΘ
  408.    John Gardiner Myers   Murray Sargent
  409.    Keld Simonsen         Arnold Winkler
  410.  
  411.  
  412. Bibliography
  413.  
  414.    [CHARSET-REG]  N. Freed, J. Postel, "IANA Charset Registration Proce-
  415.                   dures", Work in progress, <draft-freed-charset-
  416.                   reg-02.txt>, Innosoft, ISI, July 1997.
  417.  
  418.    [FSS_UTF]      X/Open CAE Specification C501 ISBN 1-85912-082-2 28cm.
  419.                   22p. pbk. 172g.  4/95, X/Open Company Ltd., "File Sys-
  420.                   tem Safe UCS Transformation Format (FSS_UTF)", X/Open
  421.                   Preleminary Specification, Document Number P316.  Also
  422.                   published in Unicode Technical Report #4.
  423.  
  424.    [ISO-10646]    ISO/IEC 10646-1:1993. International Standard -- Infor-
  425.                   mation technology -- Universal Multiple-Octet Coded
  426.                   Character Set (UCS) -- Part 1: Architecture and Basic
  427.                   Multilingual Plane.  Five amendments and a technical
  428.                   corrigendum have been published up to now.  UTF-8 is
  429.                   described in Annex R, published as Amendment 2.
  430.                   UTF-16 is described in Annex Q, published as Amendment
  431.                   1. 17 other amendments are currently at various stages
  432.                   of standardization.
  433.  
  434.    [MIME]         N. Freed, N. Borenstein, "Multipurpose Internet Mail
  435.                   Extensions (MIME) Part One:  Format of Internet Mes-
  436.                   sage Bodies", RFC 2045.  N. Freed, N. Borenstein,
  437.                   "Multipurpose Internet Mail Extensions (MIME) Part
  438.                   Two:  Media Types", RFC 2046.  K. Moore, "MIME (Multi-
  439.                   purpose Internet Mail Extensions) Part Three: Message
  440.                   Header Extensions for Non-ASCII Text", RFC 2047.  N.
  441.                   Freed, J. Klensin, J. Postel, "Multipurpose Internet
  442.                   Mail Extensions (MIME) Part Four: Registration
  443.  
  444.  
  445.  
  446.                           Expires 15 March 1998         [Page 8]
  447.  
  448. Internet Draft                    UTF-8                10 September 1998
  449.  
  450.  
  451.                   Procedures", RFC 2048.  N. Freed, N. Borenstein, "Mul-
  452.                   tipurpose Internet Mail Extensions (MIME) Part Five:
  453.                   Conformance Criteria and Examples", RFC 2049.  All
  454.                   November 1996.
  455.  
  456.    [RFC2152]      D. Goldsmith, M. Davis, "UTF-7: A Mail-safe Transfor-
  457.                   mation Format of Unicode", RFC 1642, Taligent inc.,
  458.                   May 1997. (Obsoletes RFC1642)
  459.  
  460.    [UNICODE]      The Unicode Consortium, "The Unicode Standard -- 
  461.                   Version 2.0", Addison-Wesley, 1996.
  462.  
  463.    [US-ASCII]     Coded Character Set--7-bit American Standard Code for
  464.                   Information Interchange, ANSI X3.4-1986.
  465.  
  466. Author's Address
  467.  
  468.    Franτois Yergeau
  469.    Alis Technologies
  470.    100, boul. Alexis-Nihon
  471.    Suite 600
  472.    MontrΘal  QC  H4M 2P2
  473.    Canada
  474.  
  475.    Tel: +1 (514) 747-2547
  476.    Fax: +1 (514) 747-2561
  477.    EMail: fyergeau@alis.com
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.                           Expires 15 March 1998         [Page 9]
  503.  
  504.