home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.2 / 7.2.312 < prev    next >
Encoding:
Internet Message Format  |  2009-12-01  |  9.5 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 7.2.312
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.2.312
  11. Problem:    iconv() returns an invalid character sequence when conversion
  12.         fails.  It should return an empty string. (Yongwei Wu)
  13. Solution:   Be more strict about invalid characters in the input.
  14. Files:        src/mbyte.c
  15.  
  16.  
  17. *** ../vim-7.2.311/src/mbyte.c    2009-06-16 15:23:07.000000000 +0200
  18. --- src/mbyte.c    2009-11-25 16:10:44.000000000 +0100
  19. ***************
  20. *** 133,154 ****
  21.   static int dbcs_ptr2cells_len __ARGS((char_u *p, int size));
  22.   static int dbcs_ptr2char __ARGS((char_u *p));
  23.   
  24. ! /* Lookup table to quickly get the length in bytes of a UTF-8 character from
  25. !  * the first byte of a UTF-8 string.  Bytes which are illegal when used as the
  26. !  * first byte have a one, because these will be used separately. */
  27.   static char utf8len_tab[256] =
  28.   {
  29.       1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  30.       1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  31.       1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  32.       1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  33. !     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /*bogus*/
  34. !     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /*bogus*/
  35.       2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
  36.       3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1,
  37.   };
  38.   
  39.   /*
  40.    * XIM often causes trouble.  Define XIM_DEBUG to get a log of XIM callbacks
  41.    * in the "xim.log" file.
  42.    */
  43. --- 133,172 ----
  44.   static int dbcs_ptr2cells_len __ARGS((char_u *p, int size));
  45.   static int dbcs_ptr2char __ARGS((char_u *p));
  46.   
  47. ! /*
  48. !  * Lookup table to quickly get the length in bytes of a UTF-8 character from
  49. !  * the first byte of a UTF-8 string.
  50. !  * Bytes which are illegal when used as the first byte have a 1.
  51. !  * The NUL byte has length 1.
  52. !  */
  53.   static char utf8len_tab[256] =
  54.   {
  55.       1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  56.       1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  57.       1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  58.       1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  59. !     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  60. !     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  61.       2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
  62.       3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1,
  63.   };
  64.   
  65.   /*
  66. +  * Like utf8len_tab above, but using a zero for illegal lead bytes.
  67. +  */
  68. + static char utf8len_tab_zero[256] =
  69. + {
  70. +     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  71. +     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  72. +     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  73. +     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  74. +     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  75. +     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  76. +     2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
  77. +     3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,0,0,
  78. + };
  79. + /*
  80.    * XIM often causes trouble.  Define XIM_DEBUG to get a log of XIM callbacks
  81.    * in the "xim.log" file.
  82.    */
  83. ***************
  84. *** 1352,1358 ****
  85.       if (size > 0 && *p >= 0x80)
  86.       {
  87.       if (utf_ptr2len_len(p, size) < utf8len_tab[*p])
  88. !         return 1;
  89.       c = utf_ptr2char(p);
  90.       /* An illegal byte is displayed as <xx>. */
  91.       if (utf_ptr2len(p) == 1 || c == NUL)
  92. --- 1370,1376 ----
  93.       if (size > 0 && *p >= 0x80)
  94.       {
  95.       if (utf_ptr2len_len(p, size) < utf8len_tab[*p])
  96. !         return 1;  /* truncated */
  97.       c = utf_ptr2char(p);
  98.       /* An illegal byte is displayed as <xx>. */
  99.       if (utf_ptr2len(p) == 1 || c == NUL)
  100. ***************
  101. *** 1473,1479 ****
  102.       if (p[0] < 0x80)    /* be quick for ASCII */
  103.       return p[0];
  104.   
  105. !     len = utf8len_tab[p[0]];
  106.       if (len > 1 && (p[1] & 0xc0) == 0x80)
  107.       {
  108.       if (len == 2)
  109. --- 1491,1497 ----
  110.       if (p[0] < 0x80)    /* be quick for ASCII */
  111.       return p[0];
  112.   
  113. !     len = utf8len_tab_zero[p[0]];
  114.       if (len > 1 && (p[1] & 0xc0) == 0x80)
  115.       {
  116.       if (len == 2)
  117. ***************
  118. *** 1723,1728 ****
  119. --- 1741,1747 ----
  120.   /*
  121.    * Return length of UTF-8 character, obtained from the first byte.
  122.    * "b" must be between 0 and 255!
  123. +  * Returns 1 for an invalid first byte value.
  124.    */
  125.       int
  126.   utf_byte2len(b)
  127. ***************
  128. *** 1737,1742 ****
  129. --- 1756,1762 ----
  130.    * Returns 1 for "".
  131.    * Returns 1 for an illegal byte sequence (also in incomplete byte seq.).
  132.    * Returns number > "size" for an incomplete byte sequence.
  133. +  * Never returns zero.
  134.    */
  135.       int
  136.   utf_ptr2len_len(p, size)
  137. ***************
  138. *** 1747,1757 ****
  139.       int        i;
  140.       int        m;
  141.   
  142. !     if (*p == NUL)
  143. !     return 1;
  144. !     m = len = utf8len_tab[*p];
  145.       if (len > size)
  146.       m = size;    /* incomplete byte sequence. */
  147.       for (i = 1; i < m; ++i)
  148.       if ((p[i] & 0xc0) != 0x80)
  149.           return 1;
  150. --- 1767,1779 ----
  151.       int        i;
  152.       int        m;
  153.   
  154. !     len = utf8len_tab[*p];
  155. !     if (len == 1)
  156. !     return 1;    /* NUL, ascii or illegal lead byte */
  157.       if (len > size)
  158.       m = size;    /* incomplete byte sequence. */
  159. +     else
  160. +     m = len;
  161.       for (i = 1; i < m; ++i)
  162.       if ((p[i] & 0xc0) != 0x80)
  163.           return 1;
  164. ***************
  165. *** 2505,2510 ****
  166. --- 2527,2533 ----
  167.   /*
  168.    * mb_head_off() function pointer.
  169.    * Return offset from "p" to the first byte of the character it points into.
  170. +  * If "p" points to the NUL at the end of the string return 0.
  171.    * Returns 0 when already at the first byte of a character.
  172.    */
  173.       int
  174. ***************
  175. *** 2524,2530 ****
  176.   
  177.       /* It can't be a trailing byte when not using DBCS, at the start of the
  178.        * string or the previous byte can't start a double-byte. */
  179. !     if (p <= base || MB_BYTE2LEN(p[-1]) == 1)
  180.       return 0;
  181.   
  182.       /* This is slow: need to start at the base and go forward until the
  183. --- 2547,2553 ----
  184.   
  185.       /* It can't be a trailing byte when not using DBCS, at the start of the
  186.        * string or the previous byte can't start a double-byte. */
  187. !     if (p <= base || MB_BYTE2LEN(p[-1]) == 1 || *p == NUL)
  188.       return 0;
  189.   
  190.       /* This is slow: need to start at the base and go forward until the
  191. ***************
  192. *** 2552,2558 ****
  193.        * lead byte in the current cell. */
  194.       if (p <= base
  195.           || (enc_dbcs == DBCS_JPNU && p[-1] == 0x8e)
  196. !         || MB_BYTE2LEN(p[-1]) == 1)
  197.       return 0;
  198.   
  199.       /* This is slow: need to start at the base and go forward until the
  200. --- 2575,2582 ----
  201.        * lead byte in the current cell. */
  202.       if (p <= base
  203.           || (enc_dbcs == DBCS_JPNU && p[-1] == 0x8e)
  204. !         || MB_BYTE2LEN(p[-1]) == 1
  205. !         || *p == NUL)
  206.       return 0;
  207.   
  208.       /* This is slow: need to start at the base and go forward until the
  209. ***************
  210. *** 2578,2583 ****
  211. --- 2602,2608 ----
  212.       char_u    *q;
  213.       char_u    *s;
  214.       int        c;
  215. +     int        len;
  216.   #ifdef FEAT_ARABIC
  217.       char_u    *j;
  218.   #endif
  219. ***************
  220. *** 2597,2604 ****
  221.           --q;
  222.       /* Check for illegal sequence. Do allow an illegal byte after where we
  223.        * started. */
  224. !     if (utf8len_tab[*q] != (int)(s - q + 1)
  225. !                        && utf8len_tab[*q] != (int)(p - q + 1))
  226.           return 0;
  227.   
  228.       if (q <= base)
  229. --- 2622,2629 ----
  230.           --q;
  231.       /* Check for illegal sequence. Do allow an illegal byte after where we
  232.        * started. */
  233. !     len = utf8len_tab[*q];
  234. !     if (len != (int)(s - q + 1) && len != (int)(p - q + 1))
  235.           return 0;
  236.   
  237.       if (q <= base)
  238. ***************
  239. *** 2810,2818 ****
  240.   
  241.       while (end == NULL ? *p != NUL : p < end)
  242.       {
  243. !     if ((*p & 0xc0) == 0x80)
  244.           return FALSE;    /* invalid lead byte */
  245. -     l = utf8len_tab[*p];
  246.       if (end != NULL && p + l > end)
  247.           return FALSE;    /* incomplete byte sequence */
  248.       ++p;
  249. --- 2835,2843 ----
  250.   
  251.       while (end == NULL ? *p != NUL : p < end)
  252.       {
  253. !     l = utf8len_tab_zero[*p];
  254. !     if (l == 0)
  255.           return FALSE;    /* invalid lead byte */
  256.       if (end != NULL && p + l > end)
  257.           return FALSE;    /* incomplete byte sequence */
  258.       ++p;
  259. ***************
  260. *** 6117,6128 ****
  261.           d = retval;
  262.           for (i = 0; i < len; ++i)
  263.           {
  264. !         l = utf_ptr2len(ptr + i);
  265.           if (l == 0)
  266.               *d++ = NUL;
  267.           else if (l == 1)
  268.           {
  269. !             if (unconvlenp != NULL && utf8len_tab[ptr[i]] > len - i)
  270.               {
  271.               /* Incomplete sequence at the end. */
  272.               *unconvlenp = len - i;
  273. --- 6142,6161 ----
  274.           d = retval;
  275.           for (i = 0; i < len; ++i)
  276.           {
  277. !         l = utf_ptr2len_len(ptr + i, len - i);
  278.           if (l == 0)
  279.               *d++ = NUL;
  280.           else if (l == 1)
  281.           {
  282. !             int l_w = utf8len_tab_zero[ptr[i]];
  283. !             if (l_w == 0)
  284. !             {
  285. !             /* Illegal utf-8 byte cannot be converted */
  286. !             vim_free(retval);
  287. !             return NULL;
  288. !             }
  289. !             if (unconvlenp != NULL && l_w > len - i)
  290.               {
  291.               /* Incomplete sequence at the end. */
  292.               *unconvlenp = len - i;
  293. *** ../vim-7.2.311/src/version.c    2009-12-02 13:32:10.000000000 +0100
  294. --- src/version.c    2009-12-02 15:00:23.000000000 +0100
  295. ***************
  296. *** 683,684 ****
  297. --- 683,686 ----
  298.   {   /* Add new patch number below this line */
  299. + /**/
  300. +     312,
  301.   /**/
  302.  
  303. -- 
  304. hundred-and-one symptoms of being an internet addict:
  305. 6. You refuse to go to a vacation spot with no electricity and no phone lines.
  306.  
  307.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  308. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  309. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  310.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  311.