| Index: third_party/libxml/encoding.c
|
| diff --git a/third_party/libxml/encoding.c b/third_party/libxml/encoding.c
|
| index c032a6b022e1276f628ea4debae9b7eaeb452005..0f41df9a3a8ac9c5755df6ba959ce196baa90316 100644
|
| --- a/third_party/libxml/encoding.c
|
| +++ b/third_party/libxml/encoding.c
|
| @@ -1466,7 +1466,7 @@ xmlCleanupCharEncodingHandlers(void) {
|
| void
|
| xmlRegisterCharEncodingHandler(xmlCharEncodingHandlerPtr handler) {
|
| if (handlers == NULL) xmlInitCharEncodingHandlers();
|
| - if (handler == NULL) {
|
| + if ((handler == NULL) || (handlers == NULL)) {
|
| xmlEncodingErr(XML_I18N_NO_HANDLER,
|
| "xmlRegisterCharEncodingHandler: NULL handler !\n", NULL);
|
| return;
|
| @@ -1510,6 +1510,8 @@ xmlGetCharEncodingHandler(xmlCharEncoding enc) {
|
| if (handler != NULL) return(handler);
|
| handler = xmlFindCharEncodingHandler("ebcdic");
|
| if (handler != NULL) return(handler);
|
| + handler = xmlFindCharEncodingHandler("EBCDIC-US");
|
| + if (handler != NULL) return(handler);
|
| break;
|
| case XML_CHAR_ENCODING_UCS4BE:
|
| handler = xmlFindCharEncodingHandler("ISO-10646-UCS-4");
|
| @@ -1656,14 +1658,17 @@ xmlFindCharEncodingHandler(const char *name) {
|
| }
|
| upper[i] = 0;
|
|
|
| - for (i = 0;i < nbCharEncodingHandler; i++)
|
| - if (!strcmp(upper, handlers[i]->name)) {
|
| + if (handlers != NULL) {
|
| + for (i = 0;i < nbCharEncodingHandler; i++) {
|
| + if (!strcmp(upper, handlers[i]->name)) {
|
| #ifdef DEBUG_ENCODING
|
| - xmlGenericError(xmlGenericErrorContext,
|
| - "Found registered handler for encoding %s\n", name);
|
| + xmlGenericError(xmlGenericErrorContext,
|
| + "Found registered handler for encoding %s\n", name);
|
| #endif
|
| - return(handlers[i]);
|
| - }
|
| + return(handlers[i]);
|
| + }
|
| + }
|
| + }
|
|
|
| #ifdef LIBXML_ICONV_ENABLED
|
| /* check whether iconv can handle this */
|
| @@ -1889,24 +1894,28 @@ xmlUconvWrapper(uconv_t *cd, int toUnicode, unsigned char *out, int *outlen,
|
| * The real API used by libxml for on-the-fly conversion *
|
| * *
|
| ************************************************************************/
|
| +int
|
| +xmlCharEncFirstLineInt(xmlCharEncodingHandler *handler, xmlBufferPtr out,
|
| + xmlBufferPtr in, int len);
|
|
|
| /**
|
| - * xmlCharEncFirstLine:
|
| + * xmlCharEncFirstLineInt:
|
| * @handler: char enconding transformation data structure
|
| * @out: an xmlBuffer for the output.
|
| * @in: an xmlBuffer for the input
|
| - *
|
| + * @len: number of bytes to convert for the first line, or -1
|
| + *
|
| * Front-end for the encoding handler input function, but handle only
|
| * the very first line, i.e. limit itself to 45 chars.
|
| - *
|
| - * Returns the number of byte written if success, or
|
| + *
|
| + * Returns the number of byte written if success, or
|
| * -1 general error
|
| * -2 if the transcoding fails (for *in is not valid utf8 string or
|
| * the result of transformation can't fit into the encoding we want), or
|
| */
|
| int
|
| -xmlCharEncFirstLine(xmlCharEncodingHandler *handler, xmlBufferPtr out,
|
| - xmlBufferPtr in) {
|
| +xmlCharEncFirstLineInt(xmlCharEncodingHandler *handler, xmlBufferPtr out,
|
| + xmlBufferPtr in, int len) {
|
| int ret = -2;
|
| int written;
|
| int toconv;
|
| @@ -1923,9 +1932,16 @@ xmlCharEncFirstLine(xmlCharEncodingHandler *handler, xmlBufferPtr out,
|
| * 45 chars should be sufficient to reach the end of the encoding
|
| * declaration without going too far inside the document content.
|
| * on UTF-16 this means 90bytes, on UCS4 this means 180
|
| + * The actual value depending on guessed encoding is passed as @len
|
| + * if provided
|
| */
|
| - if (toconv > 180)
|
| - toconv = 180;
|
| + if (len >= 0) {
|
| + if (toconv > len)
|
| + toconv = len;
|
| + } else {
|
| + if (toconv > 180)
|
| + toconv = 180;
|
| + }
|
| if (toconv * 2 >= written) {
|
| xmlBufferGrow(out, toconv);
|
| written = out->size - out->use - 1;
|
| @@ -1990,14 +2006,34 @@ xmlCharEncFirstLine(xmlCharEncodingHandler *handler, xmlBufferPtr out,
|
| }
|
|
|
| /**
|
| + * xmlCharEncFirstLine:
|
| + * @handler: char enconding transformation data structure
|
| + * @out: an xmlBuffer for the output.
|
| + * @in: an xmlBuffer for the input
|
| + *
|
| + * Front-end for the encoding handler input function, but handle only
|
| + * the very first line, i.e. limit itself to 45 chars.
|
| + *
|
| + * Returns the number of byte written if success, or
|
| + * -1 general error
|
| + * -2 if the transcoding fails (for *in is not valid utf8 string or
|
| + * the result of transformation can't fit into the encoding we want), or
|
| + */
|
| +int
|
| +xmlCharEncFirstLine(xmlCharEncodingHandler *handler, xmlBufferPtr out,
|
| + xmlBufferPtr in) {
|
| + return(xmlCharEncFirstLineInt(handler, out, in, -1));
|
| +}
|
| +
|
| +/**
|
| * xmlCharEncInFunc:
|
| * @handler: char encoding transformation data structure
|
| * @out: an xmlBuffer for the output.
|
| * @in: an xmlBuffer for the input
|
| - *
|
| + *
|
| * Generic front-end for the encoding handler input function
|
| - *
|
| - * Returns the number of byte written if success, or
|
| + *
|
| + * Returns the number of byte written if success, or
|
| * -1 general error
|
| * -2 if the transcoding fails (for *in is not valid utf8 string or
|
| * the result of transformation can't fit into the encoding we want), or
|
| @@ -2183,9 +2219,11 @@ retry:
|
| if (handler->output != NULL) {
|
| ret = handler->output(&out->content[out->use], &written,
|
| in->content, &toconv);
|
| - xmlBufferShrink(in, toconv);
|
| - out->use += written;
|
| - writtentot += written;
|
| + if (written > 0) {
|
| + xmlBufferShrink(in, toconv);
|
| + out->use += written;
|
| + writtentot += written;
|
| + }
|
| out->content[out->use] = 0;
|
| }
|
| #ifdef LIBXML_ICONV_ENABLED
|
| @@ -3531,3 +3569,4 @@ xmlRegisterCharEncodingHandlersISO8859x (void) {
|
|
|
| #define bottom_encoding
|
| #include "elfgcchack.h"
|
| +
|
|
|