other/password.py: alternative_password_generator ignores the requested length when the required characters exceed it
Mantenedores costumam responder em até 1 dia
@raaj-2222 já está trabalhando nisso.
Desde 25/10/2026.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 85/100
Direção de pesquisa
Abra other/password.py e leia alternative_password_generator; o bug está no bloco i -= len(chars_incl) / quotient = i // 3 / remainder = i % 3, que se comporta mal quando i fica negativo. Reproduza com os trechos da issue, depois decida entre lançar um ValueError ou limitar quando len(chars_incl) > i, e verifique se main() precisa expor esse erro. Concluído significa que ambos os casos de reprodução retornam o comprimento solicitado e o comportamento existente para entradas válidas permanece inalterado.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Python
- Estrelas
- 225k
- Forks
- 51.2k
- Merge médio
- 1d 8h
- PRs com merge (30d)
- 40
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de TheAlgorithms/Python
-
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 crashTalvez já em andamento @Nate-br assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
TheAlgorithms/Python#15636 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
ciphers/des_ecb.py: encrypt/decrypt silently corrupts any character above U+00FF (round-trip fails)Talvez já em andamento @mohammedanasnakhuda assumiu há 1 dia. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
TheAlgorithms/Python#15634 ·
Mantenedores costumam responder em até 1 dia
-
ciphers/base58.py is a copy of base64_cipher.py — no Base58 implementation exists in the fileTalvez já em andamento @SakshiYeole assumiu há 2 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 45/100
TheAlgorithms/Python#15637 ·
Mantenedores costumam responder em até 1 dia
-
hashes/adler32.py: checksum diverges from the Adler-32 spec for any non-ASCII input (sums Unicode code points instead of bytes)Talvez já em andamento @SwetaKumari7 assumiu há 2 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 35/100
TheAlgorithms/Python#15635 ·
Mantenedores costumam responder em até 1 dia
-
Optimize Node.has_loop to use constant auxiliary space instead of O(N) spaceTalvez já em andamento @mohitjoshi-hey assumiu há 12 dias. Abertaenhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 15/100
TheAlgorithms/Python#15576 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
Todas as issues de TheAlgorithms/Python
Issues semelhantes
-
No test checks that scheduled workflows declare minimal permissions, concurrency and a timeoutAbertaci enhancement testing
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia
-
area/config comp/tools P2 platform/telegram type/bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
NousResearch/hermes-agent#145412 ·
Mantenedores costumam responder em até 1 dia
-
[oblt-aw][autodoc] Update docs for security org scaffolding and Docs AI menu permission changesTalvez já em andamento @github-actions assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
Mantenedores costumam responder em até 1 dia
-
curriculum documentation quality
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
githubnext/gh-aw-workshop#5039 ·
Mantenedores costumam responder em até 1 dia
-
Community project: hosted MOSS-Image studio with a visual JSON layout builder (no ComfyUI needed)Aberta
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 65/100
OpenMOSS/MOSS-Image#27 · 1 comentário ·
Mantenedores costumam responder em até 1 dia