Changeset 3227 for libcaca


Ignore:
Timestamp:
Nov 2, 2008, 11:12:24 PM (11 years ago)
Author:
bsittler
Message:

some unicode characters could overflow the buffer; handle more control
characters and non-unicode codepoints when generating HTML.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/codec/export.c

    r3224 r3227  
    504504     * A glyph: up to 48 chars for "<td bgcolor=\"#xxxxxx\"><tt><font color=\"#xxxxxx\">"
    505505     *          up to 36 chars for "<b><i><u><blink></blink></u></i></b>"
    506      *          up to 9 chars for "&#xxxxxx;" (far less for pure ASCII)
     506     *          up to 10 chars for "&#xxxxxxx;" (far less for pure ASCII)
    507507     *          17 chars for "</font></tt></td>" */
    508     *bytes = 1000 + cv->height * (10 + maxcols * (48 + 36 + 9 + 17));
     508    *bytes = 1000 + cv->height * (10 + maxcols * (48 + 36 + 10 + 17));
    509509    cur = data = malloc(*bytes);
    510510
     
    584584                if(linechar[x + i] == CACA_MAGIC_FULLWIDTH)
    585585                    ;
    586                 else if(linechar[x + i] <= 0x00000020)
     586                else if((linechar[x + i] <= 0x00000020)
     587                        ||
     588                        ((linechar[x + i] >= 0x0000007f)
     589                         &&
     590                         (linechar[x + i] <= 0x0000009f)))
    587591                {
    588592                    /* Control characters and space converted to
     
    614618                else if(linechar[x + i] < 0x00000080)
    615619                    cur += sprintf(cur, "%c", (uint8_t)linechar[x + i]);
     620                else if((linechar[x + i] <= 0x0010fffd)
     621                        &&
     622                        ((linechar[x + i] & 0x0000fffe) != 0x0000fffe)
     623                        &&
     624                        ((linechar[x + i] < 0x0000d800)
     625                         ||
     626                         (linechar[x + i] > 0x0000dfff)))
     627                    cur += sprintf(cur, "&#%i;", (unsigned int)linechar[x + i]);
    616628                else
    617                     cur += sprintf(cur, "&#%i;", (unsigned int)linechar[x + i]);
     629                    /* non-character codepoints become U+FFFD
     630                     * REPLACEMENT CHARACTER */
     631                    cur += sprintf(cur, "&#%i;", (unsigned int)0x0000fffd);
    618632
    619633                if (((i + 1) == len) || (lineattr[x + i + 1] != lineattr[x + i]))
Note: See TracChangeset for help on using the changeset viewer.