1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-02-08 00:33:13 -08:00
emacs/lisp/url
Nacho Barrientos 0829c6836e Fix chunked encoding connections in url-http
* lisp/url/url-http.el
(url-http-chunked-encoding-after-change-function): Ensure that chunked
encoding is interpreted correctly (bug#54989).

As per [0], the last chunk of 0 bytes is always accompanied by a last
CRLF that signals the end of the message:

     chunked-body   = *chunk
                      last-chunk
                      trailer-part
                      CRLF
                      ^ this one

     chunk          = chunk-size [ chunk-ext ] CRLF
                      chunk-data CRLF
     chunk-size     = 1*HEXDIG
     last-chunk     = 1*("0") [ chunk-ext ] CRLF

     chunk-data     = 1*OCTET ; a sequence of chunk-size octets

`url-http-chunked-encoding-after-change-function' is able to process
(and remove) that terminator IF AVAILABLE in the buffer when
processing the response, however it won't wait for it if it's not yet
there.

In other words:

| Bottom of the response buffer | Bottom of the full response |
|    (visible to url-http)      | (to be delivered to Emacs)  |
| ------------------------------+-----------------------------|
| 0\r\n                         | 0\r\n                       |
|                               | \r\n                        |

If the last chunk is processed when the bottom of the response buffer
is as above (note that the whole response has not yet been delivered
to Emacs), url-http will call the user callback without waiting for
the final terminator to be read from the socket.

This is normally not an issue when doing one-shot requests, but it's
problematic when the connection is reused immediately. As there are 2
bytes from the request N that have not been dealt with, they'll be
considered as part of the response of the request N+1. On top, it
turns out that when processing the headers of request N+1,
`url-http-wait-for-headers-change-function' will consider the request
a "headerless malformed response" delivering it broken to the caller.

The proposed fix implements a state in which
`url-http-chunked-encoding-after-change-function` properly waits for
the very last element of the message preventing the problem explained
above from happening.

For additional context, this bug was found when debugging
magit/ghub (see [1] for details).

[0] https://datatracker.ietf.org/doc/html/rfc7230#section-4.1
[1] https://github.com/magit/ghub/issues/81

Copyright-paperwork-exempt: yes
2022-04-17 13:00:12 +02:00
..
ChangeLog.1
url-about.el
url-auth.el Fix problem with fetching images via Cloudflare 2022-03-06 17:41:28 +01:00
url-cache.el
url-cid.el
url-cookie.el
url-dav.el
url-dired.el
url-domsuf.el
url-expand.el
url-file.el Further fixes for eww-open-url on Tramp files 2022-02-20 22:37:04 +01:00
url-ftp.el
url-future.el
url-gw.el
url-handlers.el
url-history.el
url-http.el Fix chunked encoding connections in url-http 2022-04-17 13:00:12 +02:00
url-imap.el
url-irc.el
url-ldap.el
url-mailto.el
url-methods.el
url-misc.el
url-news.el
url-nfs.el
url-parse.el
url-privacy.el
url-proxy.el
url-queue.el Fix problem with fetching images via Cloudflare 2022-03-06 17:41:28 +01:00
url-tramp.el
url-util.el
url-vars.el * lisp/url/url-vars.el: Cosmetic changes 2022-03-15 10:18:07 -04:00
url.el