edicl / chunga

Portable chunked streams for Common Lisp
https://edicl.github.io/chunga/
Other
24 stars 9 forks source link

Add memory limits #8

Open r13l opened 3 years ago

r13l commented 3 years ago

READ-LINE* currently has no maximum line length, but will instead continue to read input until memory is exhausted. While this default should probably not be changed (there may very well be someone somewhere who is reading multi-gigabyte lines), it would enhance stability to allow callers of the library to specify a maximum line length:

(let ((chunga:*max-line-length* 8192))
  (chunga:read-line* stream))
r13l commented 3 years ago

The following program illustrates the problem (using HUNCHENTOOT, which ultimately calls CHUNGA:READ-LINE):

(ql:quickload '("hunchentoot"))
(hunchentoot:start (make-instance 'hunchentoot:easy-acceptor :port 4242))

(let ((sock (make-instance 'sb-bsd-sockets:inet-socket :type :stream :protocol :tcp))
      ss)
  (sb-bsd-sockets:socket-connect sock #(127 0 0 1) 4242)
  (setq ss (sb-bsd-sockets:socket-make-stream sock :output t :input t :buffering :none :element-type 'character :auto-close t))
  (format ss "GET / HTTP/1.0~c~c" #\Return #\Newline)
  (loop (write-char #\a ss)))