mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-10-26 03:55:04 +03:00
io: Make sure not to pass partial UTF-8 to write callback
We cannot split UTF-8 at arbitrary boundaries.
This commit is contained in:
parent
c46b89e243
commit
55ddccb645
22
xmlIO.c
22
xmlIO.c
@ -2233,23 +2233,16 @@ xmlParserInputBufferRead(xmlParserInputBufferPtr in, int len) {
|
||||
*/
|
||||
int
|
||||
xmlOutputBufferWrite(xmlOutputBufferPtr out, int len, const char *data) {
|
||||
xmlBufPtr buf = NULL;
|
||||
size_t written = 0;
|
||||
int ret;
|
||||
|
||||
if ((out == NULL) || (out->error))
|
||||
return(-1);
|
||||
if (len < 0)
|
||||
return(0);
|
||||
|
||||
while (len > 0) {
|
||||
xmlBufPtr buf = NULL;
|
||||
int chunk;
|
||||
int ret;
|
||||
|
||||
chunk = len;
|
||||
if (chunk > 256 * 1024)
|
||||
chunk = 256 * 1024;
|
||||
|
||||
ret = xmlBufAdd(out->buffer, (const xmlChar *) data, chunk);
|
||||
ret = xmlBufAdd(out->buffer, (const xmlChar *) data, len);
|
||||
if (ret != 0) {
|
||||
out->error = XML_ERR_NO_MEMORY;
|
||||
return(-1);
|
||||
@ -2284,15 +2277,13 @@ xmlOutputBufferWrite(xmlOutputBufferPtr out, int len, const char *data) {
|
||||
if (out->writecallback)
|
||||
buf = out->conv;
|
||||
else
|
||||
written += ret;
|
||||
written = ret;
|
||||
} else {
|
||||
if (out->writecallback)
|
||||
buf = out->buffer;
|
||||
else
|
||||
written += chunk;
|
||||
written = len;
|
||||
}
|
||||
data += chunk;
|
||||
len -= chunk;
|
||||
|
||||
if ((buf != NULL) && (out->writecallback)) {
|
||||
/*
|
||||
@ -2303,8 +2294,6 @@ xmlOutputBufferWrite(xmlOutputBufferPtr out, int len, const char *data) {
|
||||
|
||||
if (nbchars < MINLEN)
|
||||
break;
|
||||
if (nbchars > 256 * 1024)
|
||||
nbchars = 256 * 1024;
|
||||
|
||||
ret = out->writecallback(out->context,
|
||||
(const char *)xmlBufContent(buf), nbchars);
|
||||
@ -2325,7 +2314,6 @@ xmlOutputBufferWrite(xmlOutputBufferPtr out, int len, const char *data) {
|
||||
out->written += ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return(written <= INT_MAX ? written : INT_MAX);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user