diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-11-15 07:31:16 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:05:50 -0500 |
commit | 63a6cd624559204f9a33a6d056b99ab510fa09a6 (patch) | |
tree | a7e51a828f05d37274a55c103671b4d134ab2ccc | |
parent | 0c77d8e049b82b0d42c6216dc538713f2133a2a7 (diff) | |
download | samba-63a6cd624559204f9a33a6d056b99ab510fa09a6.tar.gz samba-63a6cd624559204f9a33a6d056b99ab510fa09a6.tar.bz2 samba-63a6cd624559204f9a33a6d056b99ab510fa09a6.zip |
r3749: don't consider it a failure if we fail to re-encode a codepoint above
1M, or in the case of non-UTF charsets, above 256
(This used to be commit 02595c14ac44403dd193d084dea9b91a67554a94)
-rw-r--r-- | source4/torture/local/iconv.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/source4/torture/local/iconv.c b/source4/torture/local/iconv.c index ab64044513..c42fa2ba0e 100644 --- a/source4/torture/local/iconv.c +++ b/source4/torture/local/iconv.c @@ -128,21 +128,7 @@ static int test_buffer(uint8_t *inbuf, size_t size, const char *charset) last_charset = charset; } -#if 0 - int i; - for (i=0;i<50;i++) { - ptr_in = inbuf; - ptr_out = buf1; - size_in1 = size; - outsize1 = sizeof(buf1); - - memset(ptr_out, 0, outsize1); - errno = 0; - ret1 = smb_iconv(cd2, &ptr_in, &size_in1, &ptr_out, &outsize1); - errno1 = errno; - } -#endif - + /* internal convert to charset - placing result in buf1 */ ptr_in = inbuf; ptr_out = buf1; size_in1 = size; @@ -153,6 +139,7 @@ static int test_buffer(uint8_t *inbuf, size_t size, const char *charset) ret1 = smb_iconv(cd2, &ptr_in, &size_in1, &ptr_out, &outsize1); errno1 = errno; + /* system convert to charset - placing result in buf2 */ ptr_in = inbuf; ptr_out = buf2; size_in2 = size; @@ -221,7 +208,8 @@ static int test_buffer(uint8_t *inbuf, size_t size, const char *charset) ok = 0; } - + + /* convert back to UTF-16, putting result in buf3 */ size = size - size_in1; ptr_in = buf1; ptr_out = buf3; @@ -230,12 +218,26 @@ static int test_buffer(uint8_t *inbuf, size_t size, const char *charset) memset(ptr_out, 0, outsize3); ret3 = smb_iconv(cd3, &ptr_in, &size_in3, &ptr_out, &outsize3); - + + /* we only internally support the first 1M codepoints */ + if (outsize3 != sizeof(buf3) - size && + get_codepoint(inbuf+sizeof(buf3) - outsize3, + size - (sizeof(buf3) - outsize3), + "UTF-16LE") >= (1<<20)) { + return ok; + } + if (ret3 != 0) { printf("pull failed - %s\n", strerror(errno)); ok = 0; } - + + if (strncmp(charset, "UTF", 3) != 0) { + /* don't expect perfect mappings for non UTF charsets */ + return ok; + } + + if (outsize3 != sizeof(buf3) - size) { printf("wrong outsize3 - %d should be %d\n", outsize3, sizeof(buf3) - size); @@ -245,8 +247,12 @@ static int test_buffer(uint8_t *inbuf, size_t size, const char *charset) if (memcmp(buf3, inbuf, size) != 0) { printf("pull bytes mismatch:\n"); show_buf("inbuf", inbuf, size); - show_buf(" buf3", buf3, size); + show_buf(" buf3", buf3, sizeof(buf3) - outsize3); ok = 0; + printf("next codepoint is %u\n", + get_codepoint(inbuf+sizeof(buf3) - outsize3, + size - (sizeof(buf3) - outsize3), + "UTF-16LE")); } if (!ok) { |