Skip to content

Fletcher32 raises IndexError on empty buffers #888

Open

Description

@RaphaelFakhri

Fletcher32 raises IndexError when it encodes an empty buffer, and when it decodes a 4-byte buffer that holds only the checksum. The other checksum codecs (CRC32, Adler32, JenkinsLookup3) round-trip empty input without error.

Reproduce

from numcodecs import Fletcher32

Fletcher32().encode(b"")
# IndexError: Out of bounds on buffer access (axis 0)

Fletcher32().decode(b"\x00\x00\x00\x00")
# IndexError: Out of bounds on buffer access (axis 0)

Tested on main (54fc274), Python 3.13, NumPy 2.

Cause

fletcher32.pyx takes &mv[0] of the payload memoryview in _fletcher32, encode, and the out branch of decode. Cython bounds-checks that index, so it fails when the memoryview is empty.

Expected

An empty payload has a Fletcher-32 checksum of 0, the same result the HDF5/netCDF reference implementation gives for a zero-length input. encode(b"") returns b"\x00\x00\x00\x00", and decoding that buffer returns an empty buffer.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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