parser_syslog: string parser raises NoMethodError on some malformed messages

クローズ 初心者向け
#5,588 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

関連するプルリクエストがすでにマージされています。

  • #5589 @yuminn-k による — マージ済み

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
ruby

調査の方向性

まずRFC3164とRFC5424の文字列パーサーのパスを読み、ここで説明されている正規表現パーサーの動作と、不正なヘッダーの処理を比較してください。RFC5424のUTF-8行を含め、issueにある3つの入力を再現してください。完了条件は、文字列パーサーが例外を発生させず、説明どおりに入力が解析されるか、一致しない行として出力されることです。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Ruby
スター
13.6k
フォーク
1.4k
平均マージ
1日 1時間
マージ済み PR(30日)
61

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fluent/fluentd のほかの issue

fluent/fluentd の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。