InterNetNews / inn

INN (InterNetNews) Usenet server
https://www.isc.org/othersoftware/#INN
Other
68 stars 12 forks source link

nnrpd hang during POST if COMPRESS DEFLATE is active but TLS is not #269

Closed enrikb closed 1 year ago

enrikb commented 1 year ago

I found the following scenario when POSTing an article with COMPRESS DEFLATE enabled, without TLS:

  1. client sends article > 512 bytes (uncompressed), but small enough (compressed) to be read at once in line_doread()
  2. in line_doread() it is inflated and fills the buffer, leaving remaining compressed data in the input buffer
  3. line_read() returns all lines it can parse from this buffer
  4. line_read() calls select() on stdin when it needs more data (only if TLS disabled)
  5. select() will only return on timeout, because the client has already sent all data, which would be available as input to inflate() in line_doread()
  6. (after timeout, the remaining data is actually processed and the article may get through ...)

This can be worked around by calling line_doread() before the select() call if (and only if) more data will be produced by the first inflate() call in line_doread(). But ensuring this might be tricky considering all possible corner cases from zlib.

Julien-Elie commented 1 year ago

Do you have a reproducible test case with an article? Any article of 600 bytes (uncompressed) for instance?

enrikb commented 1 year ago

Hi Julien, sorry for not providing more info / repro in the first place. Was just too late in the evening ... as you received some updates out-of-band, I hope that's OK now. Meanwhile I added #270 as a proposed fix. Any feedback welcome!

Julien-Elie commented 1 year ago

Hi Enrik, No problem! It's very kind of you to provide a fix. Greatly appreciated :)

I've reproduced the issue with the provided example, and your fix indeed solves it. I'll commit it soon.