ImageOps.autocontrast() raises IndexError for a one-element cutoff tuple
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 82/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
バグは src/PIL/ImageOps.py の 141〜161 行付近にある autocontrast にあります。ここでは長さを確認せずにタプルの cutoff を使っているため、要素が 1 つのタプルだと cutoff[1] が失敗します。issue のスニペットで再現してから、既存のテスト test_autocontrast_invalid_ignore の検証スタイルを確認してください。cutoff のタプルが正確に 2 要素でない場合に、わかりやすいメッセージとともに ValueError を送出し、その動作を新しいテストで確認できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
What did you do?
from PIL import Image, ImageOps
im = Image.new("L", (4, 4), 128)
ImageOps.autocontrast(im, cutoff=(10,))
What did you expect to happen?
A ValueError saying the cutoff tuple must have two elements, matching
how the same function validates its other argument: a bad ignore value
raises ValueError: ignore must be between or equal to 0 and 255
(tested in test_autocontrast_invalid_ignore). The documented shape is
"Either a tuple of (low, high), or a single number for both."
What actually happened?
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File ".../PIL/ImageOps.py", line 161, in autocontrast
cut = int(n * cutoff[1] // 100)
IndexError: tuple index out of range
What are your OS, Python and Pillow versions?
- OS: Ubuntu 24.04
- Python: 3.12.3
- Pillow: 13.1.0.dev0 (main, commit 688d01d)
Evidence
src/PIL/ImageOps.py, autocontrast, lines 141-161:
if cutoff:
# cut off pixels from both ends of the histogram
if not isinstance(cutoff, tuple):
cutoff = (cutoff, cutoff)
# get number of pixels
n = sum(h)
# remove cutoff% pixels from the low end
cut = int(n * cutoff[0] // 100)
...
# remove cutoff% samples from the high end
cut = int(n * cutoff[1] // 100)
A non-tuple cutoff is normalised to a 2-tuple, but a tuple is used as-is
with no length check, so a 1-tuple passes the if cutoff: test and then
cutoff[1] raises IndexError. A 3-tuple is silently accepted and the
extra element ignored.
- 主要言語
- Python
- スター
- 14k
- フォーク
- 2.6k
- 平均マージ
- 1日 1時間
- マージ済み PR(30日)
- 205
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python-pillow/Pillow のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
python-pillow/Pillow#10589 ·
メンテナーはふだん 1 日以内に返信
-
Sun raster files with RLE encoding and odd-width rows decode shifted対応中かも @PerryLink が 21 日前に担当しました。 オープン🤖-assisted
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
python-pillow/Pillow#10370 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Warn that pre-applying arabic_reshaper + python-bidi corrupts text on a Raqm build対応中かも @Syamjith-NK が 85 日前に担当しました。 オープンDocumentation Font Rendering PNG Third Party Framework
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
python-pillow/Pillow#9907 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Example code in ImageText documentation makes incorrect use of get_bbox()対応中かも @mmporong が今日担当しました。 オープンDocumentation
難易度 1/5 1時間未満 初心者へのやさしさ 25/100
python-pillow/Pillow#10583 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
"ImageEnhance (Color/Contrast/Brightness/Sharpness) .enhance(factor=NaN) silently returns an all-black image"再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンAwaiting OP Action
難易度 2/5 1〜3時間 初心者へのやさしさ 1/100
python-pillow/Pillow#10567 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
python-pillow/Pillow の issue をすべて見る
似ている issue
-
[Bug]: DoubleMLData.from_arrays checks the treatment d with force_all_x_finite instead of force_all_d_finite対応中かも @leninworld が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
DoubleML/doubleml-for-py#471 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
BUG: ZarrTrace fails in init_trace for models with datetime coordinates (object dtype coord array)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 2 日以内に返信
-
[Bug] Default key routing (JavaStringHash) picks a different partition than the Java client for about half of keys対応中かも @0z5a が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
apache/pulsar-client-go#1575 ·
メンテナーはふだん 2 日以内に返信