fix: 不正なテーブルのマークアップでのクラッシュとハングを修正 - #370
Merged
Merged
Conversation
- 行のないテーブルや、セルのない行だけのテーブルで解析時に例外が出ていた - rowspan/colspan/aria-rowspan/aria-colspanの不正な値がNaNや負数のまま セルのサイズになり、ヘッダー探索のArray(size)がRangeErrorを投げていた - aria-rowindex/aria-colindexの不正な値が座標をNaNにしていた - aria-rowspan/aria-colspanに上限がなく、極端な値でヘッダー探索が 数秒間ブロックしていた - rowCountを全行から求めるようにし、末尾のセルのない行や最終行を 越えるrowspanを正しく扱うようにした Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tableの解析でクラッシュする事象の調査から始めて、同じ系統の問題をまとめて修正しました。修正内容
1. 行のないテーブルでのクラッシュ
cells[cells.length - 1].reduce(...)が、行のないテーブルでundefined.reduceになっていました。あわせて
rowCountをcolCountと同じく全行から求める形に揃えています。これにより、以下も直ります。<tr></tr>があるテーブルでrowCountが 0 になっていた(クラッシュしないぶん気づきにくい不具合)rowspanが行数に反映されていなかった(HTML のテーブルモデルではテーブル高さが広がる)2.
Array(NaN)/Array(負数)による RangeErrorgetRowHeaderElements/getColHeaderElementsのArray(sizeY)Array(positionX)がRangeError: Invalid array lengthを投げていました。実際に再現を確認したもの:rowspan="abc"sizeY: NaN→ RangeErrorrowspan="-5"sizeY: -5→ RangeErroraria-colindex="abc"positionX: NaN,colCount: NaN→ RangeError不正な属性値は実際の Web ページに珍しくないため、報告されたクラッシュはこちらの可能性が高いと考えています。
3.
aria-rowspanに上限がなくページがハングするnative の
rowspanは 65534 に丸めていましたが、aria-*は素通しでした。aria-rowspan="99999999"でgetRowHeaderElementsが 約6〜7秒ブロックすることを確認しています。コンテンツスクリプトなのでページが固まります。4.
getCellが型に反してundefinedを返すreturn cell ? cell[0] : nullは配列が常に truthy なので分岐が機能しておらず、シグネチャCell | nullに反してundefinedを返していました。呼び出し元はif (cell)の truthiness 判定なので顕在化していませんでしたが、潜在バグとして修正しています。方針
各
Array()呼び出しを個別に守るのではなく、属性値のパースを入口で正規化する形にしました。parseSpanAttribute— 解釈不能・負値は HTML 仕様の既定値1に。aria-*にも native と同じ上限を適用parseIndexAttribute— 1始まりの整数でなければ属性なし扱いにフォールバック(不正なaria-colindexが rowspan 回避ループもスキップさせていた点もあわせて解消)挙動変更の注意点
aria-colspan/aria-rowspanに上限(1000 / 65534)を新設しています。実用上ありえない値の域ですが、意図的な変更です。なお
rowspan="0"は仕様上有効な値のため今回は既存挙動のまま触っていません(現状 0 スロット扱いでヘッダー紐付けから外れる別の問題が残っています)。テスト
テスト8件を追加し、
packages/table86件、全パッケージ(rules1131件・browser_extension526件ほか)、pnpm lint-fix、tsc --noEmitがすべて通っています。🤖 Generated with Claude Code