Package: mingw32-runtime
Version: 3.13-1
Severity: normal

The attached program computes basename of a 3-bytes long (which denotes 2 characters in some encodings) filename. Everything works fine if a single byte character set is used:

$ LC_ALL=pl_PL.utf8 ./test.exe
basename("\312\253\172") = "\312\253\172"

However, in the Chinese locale the last byte is truncated:

$ LC_ALL=zh_CN.utf8 ./test.exe
basename("\312\253\172") = "\312\253"


I believe the culprit is the following fragment of mingwex/basename.c:

        if( (len = wcstombs( path, refcopy, len )) != (size_t)(-1) )
          path[ len ] = '\0';

where len was previously initialized to the number of _characters_ of the input string.

Looking at implementation of dirname(), it might be affected by a similar bug as well.


-- System Information:
Debian Release: 6.0
  APT prefers unstable
  APT policy: (990, 'unstable'), (500, 'experimental'), (500, 'testing')
Architecture: i386 (x86_64)

Kernel: Linux 2.6.32-5-amd64 (SMP w/2 CPU cores)
Locale: LANG=C, LC_CTYPE=pl_PL.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

mingw32-runtime depends on no packages.

Versions of packages mingw32-runtime recommends:
ii  gcc-mingw32 [mingw32]       4.4.4-0.1+b1 The GNU Compiler Collection (cross

--
Jakub Wilk
#include <libgen.h>
#include <stdio.h>

void xprint(const char *s)
{
    while (*s)
        printf("\\%03o", (int)(unsigned char)(*s++));
}

int main(int argc, char **argv)
{
    char input[] =
        "\312\253" /* <-- CJK UNIFIED IDEOGRAPH-8BD7 encoded in CP936 */
        "z";
    char *output;
    printf("basename(\"");
    xprint(input);
    printf("\") = \"");
    output = basename(input);
    xprint(output);
    printf("\"\n");
    return 0;
}

// vim:ts=4 sw=4 et

Reply via email to