mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-02 22:41:47 -06:00
Follow-up to #1259. Before a connection authenticates, the control server read request lines with BufRead::lines, which buffers a whole line before anything looks at it, so a client that never sends `auth` could make it buffer an arbitrarily long line. Read lines with a bounded read instead. Until `auth` succeeds a line may be at most MAX_AUTH_LINE (4 KiB; the auth request is about a hundred bytes); a longer one gets a -32600 error and the connection is closed, after reading at most MAX_AUTH_LINE + 1 bytes of it. After `auth`, lines are read whole as before. End of stream, read errors and non-UTF-8 input end the connection as they did with BufRead::lines. Tests: lines_are_read_up_to_the_limit, an_overlong_line_before_auth_is_refused, long_lines_after_auth_are_still_read. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>