return((int) *ctxt->input->cur);
encoding_error:
/*
+ * An encoding problem may arise from a truncated input buffer
+ * splitting a character in the middle. In that case do not raise
+ * an error but return 0 to endicate an end of stream problem
+ */
+ if (ctxt->input->end - ctxt->input->cur < 4) {
+ *len = 0;
+ return(0);
+ }
+
+ /*
* If we detect an UTF8 error that probably mean that the
* input encoding didn't get properly advertised in the
* declaration header. Report the error and switch the encoding
{
char buffer[150];
- if (ctxt->input->cur[1] == 0) {
- snprintf(&buffer[0], 149, "Bytes: 0x%02X EOF\n",
- ctxt->input->cur[0]);
- } else if (ctxt->input->cur[2] == 0) {
- snprintf(&buffer[0], 149, "Bytes: 0x%02X 0x%02X EOF\n",
- ctxt->input->cur[0], ctxt->input->cur[1]);
- } else if (ctxt->input->cur[3] == 0) {
- snprintf(&buffer[0], 149, "Bytes: 0x%02X 0x%02X 0x%02X EOF\n",
- ctxt->input->cur[0], ctxt->input->cur[1],
- ctxt->input->cur[2]);
- } else {
- snprintf(&buffer[0], 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
- ctxt->input->cur[0], ctxt->input->cur[1],
- ctxt->input->cur[2], ctxt->input->cur[3]);
- }
+ snprintf(&buffer[0], 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
+ ctxt->input->cur[0], ctxt->input->cur[1],
+ ctxt->input->cur[2], ctxt->input->cur[3]);
__xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR,
"Input is not proper UTF-8, indicate encoding !\n%s",
BAD_CAST buffer, NULL);
*len = 1;
return ((int) *cur);
encoding_error:
+
+ /*
+ * An encoding problem may arise from a truncated input buffer
+ * splitting a character in the middle. In that case do not raise
+ * an error but return 0 to endicate an end of stream problem
+ */
+ if ((ctxt == NULL) || (ctxt->input == NULL) ||
+ (ctxt->input->end - ctxt->input->cur < 4)) {
+ *len = 0;
+ return(0);
+ }
/*
* If we detect an UTF8 error that probably mean that the
* input encoding didn't get properly advertised in the
{
char buffer[150];
- if (cur[1] == 0) {
- snprintf(&buffer[0], 149, "Bytes: 0x%02X EOF\n",
- cur[0]);
- } else if (cur[2] == 0) {
- snprintf(&buffer[0], 149, "Bytes: 0x%02X 0x%02X EOF\n",
- cur[0], cur[1]);
- } else if (cur[3] == 0) {
- snprintf(&buffer[0], 149, "Bytes: 0x%02X 0x%02X 0x%02X EOF\n",
- cur[0], cur[1], cur[2]);
- } else {
- snprintf(&buffer[0], 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
- cur[0], cur[1], cur[2], cur[3]);
- }
+ snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
+ ctxt->input->cur[0], ctxt->input->cur[1],
+ ctxt->input->cur[2], ctxt->input->cur[3]);
__xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR,
"Input is not proper UTF-8, indicate encoding !\n%s",
BAD_CAST buffer, NULL);