1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-24 13:33:01 +03:00

encoding: Move rawconsumed accounting to xmlCharEncInput

This commit is contained in:
Nick Wellnhofer
2023-08-08 15:19:51 +02:00
parent a0462e2d54
commit 4ee0815514
3 changed files with 6 additions and 29 deletions

View File

@@ -2159,6 +2159,11 @@ xmlCharEncInput(xmlParserInputBufferPtr input, int flush)
xmlBufShrink(in, c_in); xmlBufShrink(in, c_in);
xmlBufAddLen(out, c_out); xmlBufAddLen(out, c_out);
if (input->rawconsumed > ULONG_MAX - (unsigned long)c_in)
input->rawconsumed = ULONG_MAX;
else
input->rawconsumed += c_in;
if ((c_out == 0) && (ret != 0)) { if ((c_out == 0) && (ret != 0)) {
if (input->error == 0) if (input->error == 0)
input->error = xmlEncConvertError(ret); input->error = xmlEncConvertError(ret);

View File

@@ -1414,7 +1414,7 @@ xmlSwitchInputEncoding(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
* Is there already some content down the pipe to convert ? * Is there already some content down the pipe to convert ?
*/ */
if (xmlBufIsEmpty(in->buffer) == 0) { if (xmlBufIsEmpty(in->buffer) == 0) {
size_t processed, use, consumed; size_t processed;
/* /*
* Shrink the current input buffer. * Shrink the current input buffer.
@@ -1426,7 +1426,6 @@ xmlSwitchInputEncoding(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
in->raw = in->buffer; in->raw = in->buffer;
in->buffer = xmlBufCreate(); in->buffer = xmlBufCreate();
in->rawconsumed = processed; in->rawconsumed = processed;
use = xmlBufUse(in->raw);
/* /*
* TODO: We must flush and decode the whole buffer to make functions * TODO: We must flush and decode the whole buffer to make functions
@@ -1448,12 +1447,6 @@ xmlSwitchInputEncoding(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
xmlHaltParser(ctxt); xmlHaltParser(ctxt);
return (-1); return (-1);
} }
consumed = use - xmlBufUse(in->raw);
if ((consumed > ULONG_MAX) ||
(in->rawconsumed > ULONG_MAX - (unsigned long)consumed))
in->rawconsumed = ULONG_MAX;
else
in->rawconsumed += consumed;
} }
return (0); return (0);
} }

21
xmlIO.c
View File

@@ -3111,8 +3111,6 @@ xmlParserInputBufferPush(xmlParserInputBufferPtr in,
if (len < 0) return(0); if (len < 0) return(0);
if ((in == NULL) || (in->error)) return(-1); if ((in == NULL) || (in->error)) return(-1);
if (in->encoder != NULL) { if (in->encoder != NULL) {
size_t use, consumed;
/* /*
* Store the data in the incoming raw buffer * Store the data in the incoming raw buffer
*/ */
@@ -3132,16 +3130,9 @@ xmlParserInputBufferPush(xmlParserInputBufferPtr in,
/* /*
* convert as much as possible to the parser reading buffer. * convert as much as possible to the parser reading buffer.
*/ */
use = xmlBufUse(in->raw);
nbchars = xmlCharEncInput(in, 1); nbchars = xmlCharEncInput(in, 1);
if (nbchars < 0) if (nbchars < 0)
return(-1); return(-1);
consumed = use - xmlBufUse(in->raw);
if ((consumed > ULONG_MAX) ||
(in->rawconsumed > ULONG_MAX - (unsigned long)consumed))
in->rawconsumed = ULONG_MAX;
else
in->rawconsumed += consumed;
} else { } else {
nbchars = len; nbchars = len;
ret = xmlBufAdd(in->buffer, (xmlChar *) buf, nbchars); ret = xmlBufAdd(in->buffer, (xmlChar *) buf, nbchars);
@@ -3240,21 +3231,9 @@ xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) {
} }
if (in->encoder != NULL) { if (in->encoder != NULL) {
size_t use, consumed;
/*
* convert as much as possible to the parser reading buffer.
*/
use = xmlBufUse(buf);
res = xmlCharEncInput(in, 1); res = xmlCharEncInput(in, 1);
if (res < 0) if (res < 0)
return(-1); return(-1);
consumed = use - xmlBufUse(buf);
if ((consumed > ULONG_MAX) ||
(in->rawconsumed > ULONG_MAX - (unsigned long)consumed))
in->rawconsumed = ULONG_MAX;
else
in->rawconsumed += consumed;
} }
#ifdef DEBUG_INPUT #ifdef DEBUG_INPUT
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,