Skip to content

ValueError: glog(0) when encoding binary data with null bytes at capacity limit in MODE_8BIT_BYTE #423

@esolment

Description

@esolment

When encoding binary data that fills the QR code capacity exactly and ends with null bytes (\x00), qr.make() raises ValueError: glog(0) inside the Reed-Solomon implementation. This is a bug — MODE_8BIT_BYTE must handle any byte value including 0x00 per ISO 18004.

Minimal reproducible example

import qrcode
from qrcode.util import QRData, MODE_8BIT_BYTE
from qrcode.constants import ERROR_CORRECT_Q

# Version 5 + Q = 60 bytes capacity
data = b'\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x16Hello from kakaworld!!\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
assert len(data) == 60  # exactly at capacity

qr = qrcode.QRCode(version=5, error_correction=ERROR_CORRECT_Q)
qr.add_data(QRData(data, mode=MODE_8BIT_BYTE))
qr.make(fit=False)  # ValueError: glog(0)

Traceback

File ".../qrcode/base.py", line 236, in glog
    raise ValueError(f"glog({n})")
ValueError: glog(0)

Environment

  • qrcode[pil] 8.2
  • Python 3.12.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions