From 77d16c2bedc049c48eeb52d807ee741ae80d01de Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 20 Aug 2010 02:35:01 -0400 Subject: [PATCH] Zero-sized destination buffers when converting to UTF-8 shouldn't overflow. --- src/physfs.h | 10 +++++----- src/physfs_unicode.c | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/physfs.h b/src/physfs.h index c6172d80..40a4c486 100644 --- a/src/physfs.h +++ b/src/physfs.h @@ -2320,7 +2320,7 @@ PHYSFS_DECL void PHYSFS_enumerateFilesCallback(const char *dir, * * Strings that don't fit in the destination buffer will be truncated, but * will always be null-terminated and never have an incomplete UTF-8 - * sequence at the end. + * sequence at the end. If the buffer length is 0, this function does nothing. * * \param src Null-terminated source string in UCS-4 format. * \param dst Buffer to store converted UTF-8 string. @@ -2342,7 +2342,7 @@ PHYSFS_DECL void PHYSFS_utf8FromUcs4(const PHYSFS_uint32 *src, char *dst, * * Strings that don't fit in the destination buffer will be truncated, but * will always be null-terminated and never have an incomplete UCS-4 - * sequence at the end. + * sequence at the end. If the buffer length is 0, this function does nothing. * * \param src Null-terminated source string in UTF-8 format. * \param dst Buffer to store converted UCS-4 string. @@ -2365,7 +2365,7 @@ PHYSFS_DECL void PHYSFS_utf8ToUcs4(const char *src, PHYSFS_uint32 *dst, * * Strings that don't fit in the destination buffer will be truncated, but * will always be null-terminated and never have an incomplete UTF-8 - * sequence at the end. + * sequence at the end. If the buffer length is 0, this function does nothing. * * Please note that UCS-2 is not UTF-16; we do not support the "surrogate" * values at this time. @@ -2391,7 +2391,7 @@ PHYSFS_DECL void PHYSFS_utf8FromUcs2(const PHYSFS_uint16 *src, char *dst, * * Strings that don't fit in the destination buffer will be truncated, but * will always be null-terminated and never have an incomplete UCS-2 - * sequence at the end. + * sequence at the end. If the buffer length is 0, this function does nothing. * * Please note that UCS-2 is not UTF-16; we do not support the "surrogate" * values at this time. @@ -2417,7 +2417,7 @@ PHYSFS_DECL void PHYSFS_utf8ToUcs2(const char *src, PHYSFS_uint16 *dst, * * Strings that don't fit in the destination buffer will be truncated, but * will always be null-terminated and never have an incomplete UTF-8 - * sequence at the end. + * sequence at the end. If the buffer length is 0, this function does nothing. * * Please note that we do not supply a UTF-8 to Latin1 converter, since Latin1 * can't express most Unicode codepoints. It's a legacy encoding; you should diff --git a/src/physfs_unicode.c b/src/physfs_unicode.c index 0e8150f3..79ca60c1 100644 --- a/src/physfs_unicode.c +++ b/src/physfs_unicode.c @@ -305,6 +305,7 @@ static void utf8fromcodepoint(PHYSFS_uint32 cp, char **_dst, PHYSFS_uint64 *_len } /* utf8fromcodepoint */ #define UTF8FROMTYPE(typ, src, dst, len) \ + if (len == 0) return; \ len--; \ while (len) \ { \