Repository navigation
[#1804] Fix split CRLF reading in http_read_chunked_body - #1726
hardikkaurani wants to merge 1 commit into
Conversation
|
Hi @jesperpedersen, I opened this PR to fix chunked trailing
Please let me know if any adjustments are needed. |
|
LGTM |
|
Thanks for reviewing, @ecleon26! Glad |
Pranav-error
left a comment
There was a problem hiding this comment.
Fix looks right, but the test only covers the prefetched \r case. When nothing is prefetched and \r / \n come in separate reads, it isn't reached: putting back http_read_bytes(..., 2) for that path still passes. A third send covers it:
"...5\r\nHello", "\r", "\n0\r\n\r\n"Also (from reading, not run): if pgmoneta_http_create() fails, pthread_join() waits forever on the thread in accept().
pgexporter has the same code, I'll open an issue there.
2961622 to
9edbdb2
Compare
|
@Pranav-error Thanks for the review! I've updated the PR, squashed into a single commit, and rebased onto
|
|
@hardikkaurani Please, rebase |
|
@hardikkaurani please create an issue for this |
9edbdb2 to
4eeef70
Compare
Signed-off-by: Hardik Kaurani <[email protected]>
Summary
Issue - #1804
http_read_chunked_body()insrc/libpgmoneta/http.chad two bugs when reading the 2-byte trailing\r\nafter both the terminating0-size chunk and each data chunk:prefetched_size - prefetched_pos == 1(e.g., header prefetch ended on\r), theremaining_prefetched >= 2check fell intohttp_read_bytes(..., 2)without consuming that prefetched byte or advancingprefetched_pos, desynchronizing the chunk stream or failing withbytes_read != 2.http_read_bytes(..., 2)performs a singleread()/SSL_read(), so\rand\narriving in separate reads failed withbytes_read != 2.Fixes:
http_read_chunked_trailing()to read each of the 2 trailing bytes fromprefetchedfirst (when available) and fall back to single-bytehttp_read_bytes(..., 1)reads from the socket/TLS stream, and use it in both places inhttp_read_chunked_body().test_pgmoneta_http_get_chunked_split_crlfintest/testcases/test_http.ccovering split trailing\r\non both data chunks and terminating0-size chunks.Verification
clang-formatand verifiedgit diff --checkis clean.pgmoneta-testsuite will run in GitHub Actions CI.