parser_syslog: string parser raises NoMethodError on some malformed messages

Cerrado Apto para principiantes
#5,588 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Ya se ha fusionado un pull request relacionado.

  • #5589 de @yuminn-k — fusionado

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
ruby

Línea de trabajo

Empieza leyendo las rutas del parser de cadenas para RFC3164 y RFC5424 y compara cómo manejan los encabezados mal formados con el comportamiento del parser de expresiones regulares descrito aquí. Reproduce las tres entradas del issue, incluida la línea UTF-8 de RFC5424. El objetivo se cumple cuando el parser de cadenas ya no lanza excepciones y las entradas se analizan o se emiten como líneas sin coincidencia, tal como se describe.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug
Describe the bug

With parser_engine string, parser_syslog raises NoMethodError on some malformed messages that are not truncated. #5584 covers truncated messages. These are different code paths.

  1. RFC3164: the ident ends with ] but has no [. The parser subtracts from the nil result of text.index('[', cursor).
  2. RFC5424: the header contains a non-ASCII character, STRUCTURED-DATA is -, and there is no MSG. The parser compares cursor, a character index, with text.bytesize. They differ, so it slices past the end and calls chomp! on nil.
Input message_format string regexp
<14>Apr 25 16:43:29 host app]: message rfc3164 undefined method '-' for nil ident app], message message
<14>Apr 25 16:43:29 host app] message rfc3164 undefined method '-' for nil ident app], message message
<14>1 2026-04-25T16:43:29Z ホスト app 123 ID - (UTF-8) rfc5424 undefined method 'chomp!' for nil unmatched

Because the parser raises, in_tail drops these lines with invalid line found even when emit_unmatched_lines is enabled. The second case needs a UTF-8 string, for example in_tail with encoding UTF-8 or filter_parser on a UTF-8 field.

To Reproduce
  1. Create /tmp/rfc3164.log with these lines:

    <14>Apr 25 16:43:29 host app]: message
    <14>Apr 25 16:43:29 host app] message
    
  2. Create /tmp/rfc5424.log with this line in UTF-8:

    <14>1 2026-04-25T16:43:29Z ホスト app 123 ID -
    
  3. Run Fluentd with the configuration below.

Expected behavior

The parser does not raise. The RFC3164 lines are parsed as with parser_engine regexp, or reported as unmatched. The RFC5424 line is emitted as unmatched_line, as with parser_engine regexp.

Actual: all three lines are dropped with invalid line found.

Your Environment
- Fluentd version: 1.20.1 (master at f55db4b1)
- Package version: N/A (from source)
- Operating system: CachyOS
- Kernel version: 7.3.1-1-cachyos
- Ruby: 4.0.9
Your Configuration
<source>
  @type tail
  path /tmp/rfc3164.log
  pos_file /tmp/rfc3164.log.pos
  read_from_head true
  emit_unmatched_lines true
  tag rfc3164
  <parse>
    @type syslog
    message_format rfc3164
    with_priority true
    parser_engine string
  </parse>
</source>

<source>
  @type tail
  path /tmp/rfc5424.log
  pos_file /tmp/rfc5424.log.pos
  read_from_head true
  emit_unmatched_lines true
  encoding UTF-8
  tag rfc5424
  <parse>
    @type syslog
    message_format rfc5424
    with_priority true
    parser_engine string
  </parse>
</source>

<match **>
  @type stdout
</match>
Your Error Log
[warn]: invalid line found file="/tmp/rfc3164.log" line="<14>Apr 25 16:43:29 host app]: message" error="undefined method '-' for nil"
[warn]: invalid line found file="/tmp/rfc3164.log" line="<14>Apr 25 16:43:29 host app] message" error="undefined method '-' for nil"
[warn]: invalid line found file="/tmp/rfc5424.log" line="<14>1 2026-04-25T16:43:29Z ホスト app 123 ID -" error="undefined method 'chomp!' for nil"
Additional context

The RFC3164 case exists since v1.7.1. The RFC5424 case exists since v1.11.0.

Lenguaje dominante
Ruby
Estrellas
13.6k
Forks
1.4k
Merge medio
1 d 4 h
PR fusionados (30 d)
56

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de fluent/fluentd

Todos los issues de fluent/fluentd

Issues similares

Más issues de Ruby

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.