other/password.py: alternative_password_generator ignores the requested length when the required characters exceed it
メンテナーはふだん 2 日以内に返信
@raaj-2222 がすでに取り組んでいます。
2026年10月25日 から。
評価
調査の方向性
other/password.py を開いて alternative_password_generator を読んでください。バグは i -= len(chars_incl) / quotient = i // 3 / remainder = i % 3 のブロックにあり、i が負になったときに不正な動作をします。issue のスニペットで再現した上で、len(chars_incl) > i の場合に ValueError を発生させるか値をクランプするかを決め、main() がそのエラーを通知する必要があるかも確認してください。完了とは、両方の再現ケースが要求された長さを返し、有効な入力に対する既存の動作が変わらないことを意味します。
索引モデルが issue の本文から書いたものです。
説明
Repository commit
6e03a48579ca212a08b36be00378f887dc41a003
Python version (python --version)
Python 3.13.5
Dependencies version (pip freeze)
None needed — other/password.py only uses the standard library (secrets, random, string).
Expected behavior
alternative_password_generator(chars_incl, i) should return a password whose length matches the requested length i (the main() prompt calls it "the max length of your password", and the comment above the function says i = how many letters or characters the password length will be).
Actual behavior
When chars_incl is longer than the requested length i, the subtraction i -= len(chars_incl) makes i negative, and the generator silently returns a password longer than what was asked for:
>>> from other.password import alternative_password_generator
>>> len(alternative_password_generator("abcdefgh", 5)) # asked for 5
8
>>> len(alternative_password_generator("abcd", 3)) # asked for 3
5
In the second case i becomes -1, so quotient = i // 3 is -1 and remainder = i % 3 is 2 (Python's modulo of a negative number is positive), which adds one extra random letter on top of all the required characters.
A user who types a max length smaller than their required-characters string in main() gets a password that silently exceeds the max length they asked for. If the requested length is at least len(chars_incl) everything works as expected.
Steps to reproduce
python - <<'EOF'
from other.password import alternative_password_generator
print(len(alternative_password_generator("abcdefgh", 5))) # expected 5, prints 8
print(len(alternative_password_generator("abcd", 3))) # expected 3, prints 5
EOF
Suspected cause
The negative remainder path in alternative_password_generator:
i -= len(chars_incl)
quotient = i // 3
remainder = i % 3
When len(chars_incl) > i, quotient goes negative (the random() calls then contribute nothing because range() of a negative is empty) while remainder stays positive, so quotient + remainder adds extra characters. Guarding the input (if i < len(chars_incl): raise ValueError(...) or clamping) would keep the generator honest about the requested length.
- 主要言語
- Python
- スター
- 225k
- フォーク
- 51.2k
- 平均マージ
- 1日 13時間
- マージ済み PR(30日)
- 32
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TheAlgorithms/Python のほかの issue
-
binomial_distribution overflows at 171 trials even when the result is representable対応中かも @landfvit が 1 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
TheAlgorithms/Python#15656 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
continued_fraction uses float division, producing invalid terms for large integers and raising OverflowError対応中かも @trleo が 1 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
TheAlgorithms/Python#15655 · コメント 2 件 ·
メンテナーはふだん 2 日以内に返信
-
ciphers/base32.py and ciphers/base85.py encode Unicode code points instead of bytes: output diverges from the spec for non-ASCII, round-trips corrupt chars >= U+0400, arbitrary bytes crash対応中かも @Nate-br が 2 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
TheAlgorithms/Python#15636 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
ciphers/des_ecb.py: encrypt/decrypt silently corrupts any character above U+00FF (round-trip fails)対応中かも @mohammedanasnakhuda が 3 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
TheAlgorithms/Python#15634 ·
メンテナーはふだん 2 日以内に返信
-
ciphers/base58.py is a copy of base64_cipher.py — no Base58 implementation exists in the file対応中かも @SakshiYeole が 4 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 45/100
TheAlgorithms/Python#15637 ·
メンテナーはふだん 2 日以内に返信
TheAlgorithms/Python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
microsoft/agent-lightning#661 ·
メンテナーはふだん 2 日以内に返信
-
area/profiles comp/cli P3 type/feature
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
NousResearch/hermes-agent#146372 ·
メンテナーはふだん 1 日以内に返信
-
[BUG] OpenAI-compatible embedding model alias breaks embedder construction対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
[oblt-aw][autodoc] Document obs-aw-automerge contract and fix automerge doc inconsistencies対応中かも @github-actions が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
GeoSeries scale and skew tests fail with pytest 9.2.0対応中かも @jiayuasu が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信