You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ResponseTooLargeError#literal_size is false (not nil) when a line exceeds max_response_size #789
When a response exceeds max_response_size because of a long line (not a literal), Net::IMAP::ResponseTooLargeError#literal_size is false instead of nil since v0.6.4. Before v0.6.4 (and on the v0.5 / v0.4 branches) it is nil.
Reproduction
require"net/imap"require"socket"putsRUBY_DESCRIPTIONputs"net-imap #{Net::IMAP::VERSION}"deftry(label,payload)server=TCPServer.new("127.0.0.1",0)th=Thread.newdosock=server.acceptsock.write"* OK ready\r\n"sock.writepayloadsleep1sock.closeendimap=Net::IMAP.new("127.0.0.1",port: server.addr[1],max_response_size: 100)imap.nooprescueNet::IMAP::ResponseTooLargeError=>eprintf"%-8s bytes_read=%p literal_size=%p max_response_size=%p\n",label,e.bytes_read,e.literal_size,e.max_response_sizeensureimap&.disconnectrescuenilth&.joinserver&.closeendtry"line","* " + "a" * 300 + "\r\n"try"literal","* 1 FETCH (BODY[] {200}\r\n" + "a" * 200 + ")\r\n"
Output
ruby 4.1.0dev (2026-11-09T07:44:48Z HEAD 4f0a0a0eca) +PRISM [x86_64-linux]
net-imap 0.6.8
line bytes_read=100 literal_size=false max_response_size=100
literal bytes_read=25 literal_size=200 max_response_size=100
Since 6f82e28 ("Faster ResponseReader: parse literal from line", #642), read_line stores that value in @literal_sizebeforeguard_response_too_large! runs, so the false is passed to ResponseTooLargeError.new. On the v0.5 / v0.4 branches the same get_literal_size was backported, but there the error is raised before @literal_size is assigned, so they are not affected.
The error message is unaffected (response_size_msg treats false as falsy); only the attribute value differs.
I have opened a PR, using the guard you suggested.
Checked what else reads the value, in case nil instead of false mattered anywhere: done? is line_done? && !literal_size and min_response_remaining uses literal_size || 0, so both treat false and nil the same, and response_size_msg already treats false as falsy. Only the attribute differs, which is what the literal_size: nil default on ResponseTooLargeError#initialize implies anyway.
The test covers both halves, since the fix should not stop a real literal from being reported: an oversized line now gives literal_size nil, and an oversized literal still gives 200. It fails on master with <false> was expected to be nil.
Activity
ihamzatarar commentedon Nov 17, 2026
I have opened a PR, using the guard you suggested.
Checked what else reads the value, in case nil instead of false mattered anywhere:
done?isline_done? && !literal_sizeandmin_response_remainingusesliteral_size || 0, so both treatfalseandnilthe same, andresponse_size_msgalready treatsfalseas falsy. Only the attribute differs, which is what theliteral_size: nildefault onResponseTooLargeError#initializeimplies anyway.The test covers both halves, since the fix should not stop a real literal from being reported: an oversized line now gives
literal_sizenil, and an oversized literal still gives 200. It fails on master with<false> was expected to be nil.