* xmlParserGrow: * @ctxt: an XML parser context * * Grow the input buffer. * * Returns the number of bytes read or -1 in case of error. */
| 438 | * Returns the number of bytes read or -1 in case of error. |
| 439 | */ |
| 440 | int |
| 441 | xmlParserGrow(xmlParserCtxtPtr ctxt) { |
| 442 | xmlParserInputPtr in = ctxt->input; |
| 443 | xmlParserInputBufferPtr buf = in->buf; |
| 444 | size_t curEnd = in->end - in->cur; |
| 445 | size_t curBase = in->cur - in->base; |
| 446 | size_t maxLength = (ctxt->options & XML_PARSE_HUGE) ? |
| 447 | XML_MAX_HUGE_LENGTH : |
| 448 | XML_MAX_LOOKUP_LIMIT; |
| 449 | int ret; |
| 450 | |
| 451 | if (buf == NULL) |
| 452 | return(0); |
| 453 | /* Don't grow push parser buffer. */ |
| 454 | if (PARSER_PROGRESSIVE(ctxt)) |
| 455 | return(0); |
| 456 | /* Don't grow memory buffers. */ |
| 457 | if ((buf->encoder == NULL) && (buf->readcallback == NULL)) |
| 458 | return(0); |
| 459 | if (buf->error != 0) |
| 460 | return(-1); |
| 461 | |
| 462 | if (curBase > maxLength) { |
| 463 | xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT, |
| 464 | "Buffer size limit exceeded, try XML_PARSE_HUGE\n"); |
| 465 | xmlHaltParser(ctxt); |
| 466 | return(-1); |
| 467 | } |
| 468 | |
| 469 | if (curEnd >= INPUT_CHUNK) |
| 470 | return(0); |
| 471 | |
| 472 | ret = xmlParserInputBufferGrow(buf, INPUT_CHUNK); |
| 473 | xmlBufUpdateInput(buf->buffer, in, curBase); |
| 474 | |
| 475 | if (ret < 0) { |
| 476 | xmlCtxtErrIO(ctxt, buf->error, NULL); |
| 477 | } |
| 478 | |
| 479 | return(ret); |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * xmlParserInputGrow: |
no test coverage detected