Changeset 91 in libcf


Ignore:
Timestamp:
05/19/13 13:24:43 (11 years ago)
Author:
cheese
Message:

#1 fix base64 bug

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cf_codec.c

    r90 r91  
    7777 *
    7878 * @remark
    79  * hex는 할당된 메모리이며, 크기는 '\0'를 포함하여 len * 2 + 1
     79 * hex는 할당된 메모리이며, 크기는 '\0'를 제외하고 len * 2
    8080 */
    8181int
     
    172172 *
    173173 * @remark
    174  * base64는 할당된 메모리이며, 크기는 ((len + 2) / 3) * 4
    175  * (null-character 제외)
     174 * base64는 할당된 메모리이며, 크기는 '\0'를 제외하고 ((len + 2) / 3) * 4
    176175 */
    177176int
     
    209208        if (src - bin == len - 1)
    210209        {
    211             *dst++ = g_table_Base64Encode[SEXTUPLE_E_2 (bin)];
     210            *dst++ = g_table_Base64Encode[SEXTUPLE_E_2 (src)];
    212211            *dst++ = g_table_Base64Encode[BASE64_PADDING_CHAR_INDEX];
    213212        }
    214213        else
    215214        {
    216             *dst++ = g_table_Base64Encode[SEXTUPLE_E_2 (bin)|
    217                                           SEXTUPLE_E_3 (bin)];
    218             *dst++ = g_table_Base64Encode[SEXTUPLE_E_4 (bin)];
     215            *dst++ = g_table_Base64Encode[SEXTUPLE_E_2 (src)|
     216                                          SEXTUPLE_E_3 (src)];
     217            *dst++ = g_table_Base64Encode[SEXTUPLE_E_4 (src)];
    219218        }
    220219
     
    235234 *
    236235 * @remark
    237  * base64는 할당된 메모리이며, 크기는 (strlen (base64) - <패딩 길이>) / 4 * 3
     236 * base64는 할당된 메모리이며, 크기는 (strlen (base64)) / 4 * 3
    238237 */
    239238int
     
    241240                        unsigned char   * bin)
    242241{
    243     int             remain = 0;
    244242    const char      * src = base64;
    245243    unsigned char   * dst = bin;
     244    int             remain = 0;
    246245    int             binlen = 0;
    247246
     
    251250    while (g_ascii_Base64Decode[(int)*src] < BASE64_PADDING_CHAR_INDEX) src++;
    252251
    253     if (*src)
     252    if (*src == 0xff)
    254253        return CF_ERROR_CODEC_NOT_BASE64;
    255254
    256255    remain = (int)(src - base64);
    257     binlen = ((remain + 3) / 4) * 3;
     256    binlen = ((remain + 2/* max padding length */) / 4) * 3;
    258257
    259258#define SEXTUPLE_D_1(src)   (g_ascii_Base64Decode[(int)src[0]] << 2)
     
    264263#define SEXTUPLE_D_6(src)   (g_ascii_Base64Decode[(int)src[3]]     )
    265264
    266     for (src = base64, dst = bin ; remain > 4 ; remain -= 4, src += 4)
     265    for (src = base64 ; remain > 4 ; remain -= 4, src += 4)
    267266    {
    268267        *dst++ = (unsigned char)(SEXTUPLE_D_1 (src) | SEXTUPLE_D_2 (src));
     
    278277        *dst++ = (unsigned char)(SEXTUPLE_D_5 (src) | SEXTUPLE_D_6 (src));
    279278
    280     return binlen;
    281 }
     279    return binlen - (4 % remain);
     280}
Note: See TracChangeset for help on using the changeset viewer.