ResponseTooLargeError#literal_size is false (not nil) when a line exceeds max_response_size
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 77/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- ruby
- Área
- backend, networking
Línea de trabajo
Empieza con get_literal_size en lib/net/imap/response_reader.rb y las pruebas del lector de respuestas en test/net/imap/test_response_reader.rb, ambos identificados en el issue. Reproduce el caso de la línea larga y comprueba cómo llega el valor devuelto a ResponseTooLargeError#literal_size. El trabajo estará terminado cuando el caso de la línea devuelva nil y las respuestas literales sigan indicando su tamaño.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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"
puts RUBY_DESCRIPTION
puts "net-imap #{Net::IMAP::VERSION}"
def try(label, payload)
server = TCPServer.new("127.0.0.1", 0)
th = Thread.new do
sock = server.accept
sock.write "* OK ready\r\n"
sock.write payload
sleep 1
sock.close
end
imap = Net::IMAP.new("127.0.0.1", port: server.addr[1], max_response_size: 100)
imap.noop
rescue Net::IMAP::ResponseTooLargeError => e
printf "%-8s bytes_read=%p literal_size=%p max_response_size=%p\n",
label, e.bytes_read, e.literal_size, e.max_response_size
ensure
imap&.disconnect rescue nil
th&.join
server&.close
end
try "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
ruby 4.0.9 (2026-10-23 revision 3e93b23afc) +PRISM [x86_64-linux]
net-imap 0.6.4.1
line bytes_read=100 literal_size=false max_response_size=100
literal bytes_read=25 literal_size=200 max_response_size=100
ruby 4.0.0 (2025-12-25 revision 553f1675f3) +PRISM [x86_64-linux]
net-imap 0.6.2
line bytes_read=100 literal_size=nil max_response_size=100
literal bytes_read=25 literal_size=200 max_response_size=100
ruby 3.4.12 (2026-10-23 revision 366f5fdc00) +PRISM [x86_64-linux]
net-imap 0.5.15
line bytes_read=100 literal_size=nil max_response_size=100
literal bytes_read=25 literal_size=200 max_response_size=100
Expected
literal_size is nil for the "line" case, as in v0.6.2 and v0.5.15 (and as the literal_size: nil default of ResponseTooLargeError#initialize suggests).
Cause
ResponseReader#get_literal_size returns false when the line does not end with a literal prefix:
https://github.com/ruby/net-imap/blob/v0.6.8/lib/net/imap/response_reader.rb#L50-L52
Since 6f82e28 ("Faster ResponseReader: parse literal from line", #642), read_line stores that value in @literal_size before guard_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.
Possible fix
def get_literal_size(buff)
- buff.end_with?("}\r\n") && buff.rindex(/\{(\d+)\}\r\n\z/n) &&
- coerce_number64($1)
+ return unless buff.end_with?("}\r\n") && buff.rindex(/\{(\d+)\}\r\n\z/n)
+ coerce_number64($1)
rescue DataFormatError
I can open a PR with this change and a test in test/net/imap/test_response_reader.rb if that helps.
🤖 Generated with Claude Code
- Lenguaje dominante
- Ruby
- Estrellas
- 121
- Forks
- 47
- Merge medio
- 19 h 25 min
- PR fusionados (30 d)
- 3
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de ruby/net-imap
-
bug
Dificultad 5/5 Más de una semana Aptitud para principiantes 30/100
-
Cannot use FakeServerAbierto
Dificultad 3/5 1-2 días Aptitud para principiantes 25/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
Todos los issues de ruby/net-imap
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
Websockify heartbeat for vnc_containerPosiblemente ocupada @robinkar la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
needs verification
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 7 días
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
akitaonrails/ai-book-2026#13 ·
-
Mend: dependency security vulnerability
Dificultad 2/5 1-3 horas Aptitud para principiantes 63/100
Los mantenedores suelen responder en 1 día