| 592 | } |
| 593 | |
| 594 | static int DoraXrtHttpProcessChunkedBody(DoraXrtHttpStreamContext* ctx) { |
| 595 | for (;;) { |
| 596 | if (ctx->chunkTerminated) { |
| 597 | return DoraXrtHttpProcessChunkedTrailers(ctx); |
| 598 | } |
| 599 | if (ctx->chunkRemaining == 0u) { |
| 600 | size_t lineEnd = DoraXrtHttpFindBytes(ctx->pending, ctx->pendingLen, "\r\n", 2u); |
| 601 | size_t nextSize = 0u; |
| 602 | if (lineEnd == (size_t)-1) { |
| 603 | if (ctx->pendingLen > XCODEC_HTTP1_HEADER_MAX_LENGTH) { |
| 604 | DoraXrtHttpStreamCloseWith(ctx, XRT_NET_ERROR); |
| 605 | return 0; |
| 606 | } |
| 607 | return 1; |
| 608 | } |
| 609 | if (lineEnd + 2u > XCODEC_HTTP1_HEADER_MAX_LENGTH) { |
| 610 | DoraXrtHttpStreamCloseWith(ctx, XRT_NET_ERROR); |
| 611 | return 0; |
| 612 | } |
| 613 | if (!DoraXrtHttpParseChunkSize(ctx->pending, lineEnd, &nextSize)) { |
| 614 | DoraXrtHttpStreamCloseWith(ctx, XRT_NET_ERROR); |
| 615 | return 0; |
| 616 | } |
| 617 | DoraXrtHttpStreamConsume(ctx, lineEnd + 2u); |
| 618 | if (nextSize == 0u) { |
| 619 | ctx->chunkTerminated = 1; |
| 620 | continue; |
| 621 | } |
| 622 | ctx->chunkRemaining = nextSize; |
| 623 | } |
| 624 | if (ctx->chunkRemaining > SIZE_MAX - 2u) { |
| 625 | DoraXrtHttpStreamCloseWith(ctx, XRT_NET_ERROR); |
| 626 | return 0; |
| 627 | } |
| 628 | if (ctx->pendingLen < ctx->chunkRemaining + 2u) { |
| 629 | return 1; |
| 630 | } |
| 631 | if (ctx->pending[ctx->chunkRemaining] != '\r' || ctx->pending[ctx->chunkRemaining + 1u] != '\n') { |
| 632 | DoraXrtHttpStreamCloseWith(ctx, XRT_NET_ERROR); |
| 633 | return 0; |
| 634 | } |
| 635 | ctx->received += ctx->chunkRemaining; |
| 636 | if (!DoraXrtHttpDeliverChunk(ctx, ctx->pending, ctx->chunkRemaining, 0u)) { |
| 637 | return 0; |
| 638 | } |
| 639 | DoraXrtHttpStreamConsume(ctx, ctx->chunkRemaining + 2u); |
| 640 | ctx->chunkRemaining = 0u; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | static int DoraXrtHttpProcessCloseDelimitedBody(DoraXrtHttpStreamContext* ctx) { |
| 645 | if (ctx->pendingLen == 0u) { |
no test coverage detected