EddyRivasLab / easel

Sequence analysis library used by Eddy/Rivas lab code
Other
46 stars 26 forks source link

esl_buffer hangs when input ends in \r #23

Closed cryptogenomicon closed 6 years ago

cryptogenomicon commented 6 years ago

Linode reported an alarm for 2hr 100% CPU on our server. R-scape was hung on a user input. Traced the problem, and it's that the input ends in a \r carriage return with no newline. esl_buffer sees this as an incomplete newline (i.e. possibly a Windows \r\n) and mishandles it, trying to load more data to check for the expected \n. Any input (file, stream) that ends in \r will cause esl_buffer-based reads to hang.

The incorrect code is in esl_buffer.c::buffer_countline(), in the first do loop, currently lines 1755..1761.

cryptogenomicon commented 6 years ago

Fixed in e41215c, which also adds a unit test that detects this bug.