summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/libxml/src/encoding.c
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/libxml/src/encoding.c')
-rw-r--r--chromium/third_party/libxml/src/encoding.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/chromium/third_party/libxml/src/encoding.c b/chromium/third_party/libxml/src/encoding.c
index 5e50c1537f0..3741c94ec48 100644
--- a/chromium/third_party/libxml/src/encoding.c
+++ b/chromium/third_party/libxml/src/encoding.c
@@ -527,7 +527,7 @@ UTF16LEToUTF8(unsigned char* out, int *outlen,
in++;
}
if ((c & 0xFC00) == 0xD800) { /* surrogates */
- if (in >= inend) { /* (in > inend) shouldn't happens */
+ if (in >= inend) { /* handle split mutli-byte characters */
break;
}
if (xmlLittleEndian) {
@@ -744,38 +744,39 @@ UTF16BEToUTF8(unsigned char* out, int *outlen,
{
unsigned char* outstart = out;
const unsigned char* processed = inb;
- unsigned char* outend = out + *outlen;
+ unsigned char* outend;
unsigned short* in = (unsigned short*) inb;
unsigned short* inend;
unsigned int c, d, inlen;
unsigned char *tmp;
int bits;
+ if (*outlen == 0) {
+ *inlenb = 0;
+ return(0);
+ }
+ outend = out + *outlen;
if ((*inlenb % 2) == 1)
(*inlenb)--;
inlen = *inlenb / 2;
inend= in + inlen;
- while (in < inend) {
+ while ((in < inend) && (out - outstart + 5 < *outlen)) {
if (xmlLittleEndian) {
tmp = (unsigned char *) in;
c = *tmp++;
- c = c << 8;
- c = c | (unsigned int) *tmp;
+ c = (c << 8) | (unsigned int) *tmp;
in++;
} else {
c= *in++;
}
if ((c & 0xFC00) == 0xD800) { /* surrogates */
- if (in >= inend) { /* (in > inend) shouldn't happens */
- *outlen = out - outstart;
- *inlenb = processed - inb;
- return(-2);
+ if (in >= inend) { /* handle split mutli-byte characters */
+ break;
}
if (xmlLittleEndian) {
tmp = (unsigned char *) in;
d = *tmp++;
- d = d << 8;
- d = d | (unsigned int) *tmp;
+ d = (d << 8) | (unsigned int) *tmp;
in++;
} else {
d= *in++;
@@ -1822,7 +1823,7 @@ xmlIconvWrapper(iconv_t cd, unsigned char *out, int *outlen,
size_t icv_inlen, icv_outlen;
const char *icv_in = (const char *) in;
char *icv_out = (char *) out;
- int ret;
+ size_t ret;
if ((out == NULL) || (outlen == NULL) || (inlen == NULL) || (in == NULL)) {
if (outlen != NULL) *outlen = 0;
@@ -1833,7 +1834,7 @@ xmlIconvWrapper(iconv_t cd, unsigned char *out, int *outlen,
ret = iconv(cd, (ICONV_CONST char **) &icv_in, &icv_inlen, &icv_out, &icv_outlen);
*inlen -= icv_inlen;
*outlen -= icv_outlen;
- if ((icv_inlen != 0) || (ret == -1)) {
+ if ((icv_inlen != 0) || (ret == (size_t) -1)) {
#ifdef EILSEQ
if (errno == EILSEQ) {
return -2;
@@ -2495,7 +2496,7 @@ retry:
*/
toconv = xmlBufUse(in);
if (toconv == 0)
- return (0);
+ return (writtentot);
if (toconv > 64 * 1024)
toconv = 64 * 1024;
if (toconv * 4 >= written) {