diff options
author | Nacho Barrientos <nacho.barrientos@cern.ch> | 2022-04-17 13:00:12 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2022-04-17 13:00:12 +0200 |
commit | 0829c6836eff14dda0cf8b3047376967f7b000f4 (patch) | |
tree | ea89c7688e9ffdd2976e932c675e473570eb26b2 /lisp/emacs-lisp/lisp-mode.el | |
parent | 60a3c94a14da8c9f4fa591bea25ea5189d92fe7a (diff) | |
download | emacs-0829c6836eff14dda0cf8b3047376967f7b000f4.tar.gz emacs-0829c6836eff14dda0cf8b3047376967f7b000f4.tar.bz2 emacs-0829c6836eff14dda0cf8b3047376967f7b000f4.zip |
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
Diffstat (limited to 'lisp/emacs-lisp/lisp-mode.el')
0 files changed, 0 insertions, 0 deletions