[gmime-devel] Issue with header decoding

Hey all,

I came across this header: "=?windows-1255?Q?=E1?=" which should decode to a single character, 
in the following reproduction code, decoding s0 returns an empty string and only after adding "=00" i get the expected result.

    char *s0 = "=?windows-1255?Q?=E1?=";
    char *s1 = "=?windows-1255?Q?=E1=00?=";

    printf("'%s' -> '%s'\n", s0, g_mime_utils_header_decode_text(s0));
    printf("'%s' -> '%s'\n", s1, g_mime_utils_header_decode_text(s1));

# ./gmime_decode 
'=?windows-1255?Q?=E1?=' -> ''
'=?windows-1255?Q?=E1=00?=' -> 'ב'

I've tried both gmime-2.4 and 2.6, on 3 different linux platforms (gentoo,arch,centos) and after digging in the sources, I noticed that iconv behaves unexpectedly when asked to decode a single char. follows code to confirm:

#include <stdio.h>
#include <iconv.h>
#include <stdlib.h>

int main(int argc, char **argv)
    iconv_t cd = iconv_open("utf-8","windows-1255");
    int insize = strtol(argv[1],0,10);

    char inbuf[2] = { 225, 0 };
    char outbuf[10];

    char *inptr = inbuf;
    char *wrptr = outbuf;
    size_t avail = 10;

    int rc = iconv (cd, &inptr, &insize, &wrptr, &avail);

    printf("rc: %d, avail: %d, decoded: %s\n", rc, avail, outbuf);

    return 0;

# gcc test.c 
# ./a.out 1
rc: 0, avail: 10, decoded: ü§¿%Þá
# ./a.out 2
rc: 0, avail: 7, decoded: ב

I've noticed that in gmime-utils.c such behavior occurs when decoding the header in question:

i.e, declen=1
<code gmime-utils.c>
size_t n = charset_convert (cd, (char *) decoded, declen, &buf, &len, &ninval);

What's the recommended tactic resolving this issue?
Should I detect and fix such headers before trying to decode them?

Best Regards.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]