Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

hashes/adler32.py: checksum diverges from the Adler-32 spec for any non-ASCII input (sums Unicode code points instead of bytes)

Aperta
#15,635 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@SwetaKumari7 ci sta già lavorando.

Dal 24/10/2026.

  • #1 di @SwetaKumari7 — aperta
  • #15642 di @saiyam-jain-dev — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
databases

Direzione di ricerca

The bug is in hashes/adler32.py: adler32() sums ord() per Unicode character instead of per byte. Fix by encoding the input to UTF-8 first (or accepting bytes), mirroring how the sibling hashes/crc32.py already works against zlib.crc32. Verify with the issue's reproduction snippet comparing against zlib.adler32(text.encode()) for non-ASCII strings like '€100' and '日本語テスト', and update the doctests which only cover ASCII. Note an open pull request is already linked, so check whether work is under way before starting.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Repository commit

6e03a48579ca212a08b36be00378f887dc41a003

Python version (python --version)

Python 3.13.5

Dependencies version (pip freeze)

None needed — hashes/adler32.py only uses the standard library.

Expected behavior

Adler-32 is defined over a byte stream, so adler32(text) should produce the same value as the reference implementation on the text's UTF-8 bytes (zlib.adler32(text.encode())), for any input text. The sibling module hashes/crc32.py does exactly this (it takes bytes and matches zlib.crc32 for every input).

Actual behavior

adler32 iterates Unicode code points and sums ord(char), so it only matches the real Adler-32 for pure-ASCII text. Every non-ASCII character silently produces a checksum that no standard implementation would produce:

>>> from hashes.adler32 import adler32
>>> import zlib
>>> adler32('Algorithms')
363791387
>>> zlib.adler32('Algorithms'.encode())
363791387
>>> adler32('€100')
2211914046
>>> zlib.adler32('€100'.encode())
196018850
>>> adler32('日本語テスト')
3064850950
>>> zlib.adler32('日本語テスト'.encode())
2053180537

For a checksum/integrity algorithm, producing values that disagree with every other Adler-32 implementation (zlib, Python's zlib.adler32, etc.) for non-ASCII input makes the results unusable for verification.

Steps to reproduce

python - <<'EOF'
from hashes.adler32 import adler32
import zlib
for s in ['Algorithms', 'héllo', '€100', '日本語テスト']:
    print(s, adler32(s), zlib.adler32(s.encode()), adler32(s) == zlib.adler32(s.encode()))
EOF

Output: only 'Algorithms' matches; the other three lines end with False.

Suspected cause

hashes/adler32.py (adler32(plain_text: str)) uses a = (a + ord(plain_chr)) % MOD_ADLER per character. Encoding the input to UTF-8 first (like crc32.py already requires bytes) would keep it on-spec for all inputs; the doctests only cover ASCII strings, so this never shows up in the test run.

Lingua principale
Python
Stelle
225k
Fork
51.2k
Merge medio
1g 8h
PR unite (30g)
40

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TheAlgorithms/Python

Tutte le issue di TheAlgorithms/Python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.