[🐛 Bug]: [py] A BiDi event payload nested too deeply closes the WebSocket connection

オープン 初心者向け
#18,438 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

まだ誰も着手していません。

評価

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

調査の方向性

py/selenium/webdriver/common/_bidi/dispatcher.pyを読み、EventDispatcher.receiveとBiDiSerializationErrorの処理に注目してください。提供された深くネストされたscript.messageペイロードで障害を再現し、RecursionErrorがログに記録され、接続を閉じることなくイベントが破棄されることを確認してください。セッション上の後続のコマンドとイベントが引き続き動作すれば完了です。

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

説明

C-py I-defect
Description

A BiDi event whose payload is nested too deeply for Record.from_json to read closes the WebSocket connection instead of being dropped, so every later command and event on that session fails.

EventDispatcher.receive (py/selenium/webdriver/common/_bidi/dispatcher.py) deserializes each event on the socket's reader thread and only catches BiDiSerializationError. from_json reads nested typed values recursively (a script array value costs several frames per level), so a value nested about 190 levels deep raises RecursionError. That escapes to websocket-client's on_error, and WebSocketConnection._start_ws closes the socket there. json.loads accepts the same payload, since it handles about 990 nested JSON levels.

Command results are read on the caller's thread, so there the RecursionError reaches the caller and the connection stays open.

Suggested fix: have EventDispatcher.receive also catch RecursionError and log and drop the payload, as it already does for one that fails validation.

Reproducible Code
from selenium.webdriver.common._bidi.script import MessageParameters

value = {"type": "undefined"}
for _ in range(250):
    value = {"type": "array", "value": [value]}

# The params of a script.message event; raises RecursionError (Python 3.10, default recursion limit)
MessageParameters.from_json({"channel": "c", "data": value, "source": {"realm": "r"}})

With a listener added through Script(...).add_message_listener(...), the same params arriving as a script.message event close the connection.

主要言語
Java
スター
34.6k
フォーク
8.7k
平均マージ
1日 16時間
マージ済み PR(30日)
107

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

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

SeleniumHQ/selenium のほかの issue

SeleniumHQ/selenium の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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