other/password.py: alternative_password_generator ignores the requested length when the required characters exceed it
維護者通常 1 天內回覆
評估
研究方向
打開 other/password.py 並閱讀 alternative_password_generator;bug 位於 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 天 8 小時
- 30 天內合併 PR
- 40
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
TheAlgorithms/Python 的其他 Issue
-
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 於 1 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 88/100
TheAlgorithms/Python#15636 · 1 則留言 ·
維護者通常 1 天內回覆
-
ciphers/des_ecb.py: encrypt/decrypt silently corrupts any character above U+00FF (round-trip fails)可能已有人在做 @mohammedanasnakhuda 於 2 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 88/100
TheAlgorithms/Python#15634 ·
維護者通常 1 天內回覆
-
ciphers/base58.py is a copy of base64_cipher.py — no Base58 implementation exists in the file可能已有人在做 @SakshiYeole 於 3 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 45/100
TheAlgorithms/Python#15637 ·
維護者通常 1 天內回覆
-
hashes/adler32.py: checksum diverges from the Adler-32 spec for any non-ASCII input (sums Unicode code points instead of bytes)可能已有人在做 @SwetaKumari7 於 3 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 35/100
TheAlgorithms/Python#15635 ·
維護者通常 1 天內回覆
-
Optimize Node.has_loop to use constant auxiliary space instead of O(N) space可能已有人在做 @mohitjoshi-hey 於 13 天前認領。 未關閉enhancement
難度 2/5 1-3 小時 新手友好度 15/100
TheAlgorithms/Python#15576 · 1 則留言 ·
維護者通常 1 天內回覆
查看 TheAlgorithms/Python 的全部 Issue
相似的 Issue
-
fix(ui): serve bundled fonts from the gateway可能已有人在做 @dkritarth 今天認領。 未關閉agent: in-progress agent: ready P3 type: bug
難度 2/5 1-3 小時 新手友好度 72/100
dkritarth/scopewatch#336 · 1 則留言 ·
維護者通常 1 天內回覆
-
bob
難度 1/5 1-3 小時 新手友好度 72/100
khuisman/mcp-gee-sweet#1267 ·
維護者通常 1 天內回覆
-
bug confirmed issue
難度 2/5 1-3 小時 新手友好度 68/100
open-webui/open-webui#33285 · 1 則留言 ·
維護者通常 1 天內回覆
-
tv-list
難度 2/5 1-3 小時 新手友好度 66/100
Gathin23/cleanyourtv#2337 ·
維護者通常 1 天內回覆
-
bug P2
難度 2/5 1-3 小時 新手友好度 84/100
維護者通常 1 天內回覆