Skip to content

Exception on empty input #24

Description

@Alezy80

When input is empty array/span all hashes throws an exception.

var bytes = new byte[0];
var hash = xxHash3.ComputeHash(bytes, bytes.Length); //exception

var span = bytes.AsSpan();
var hash2 = xxHash3.ComputeHash(span, span.Length); //exception

In all hash functions must be guard clause like this

if (data.Length == 0)
    return ComputeEmptyHash(seed);
...
private static unsafe uint ComputeEmptyHash(uint seed)
{
    var pData = stackalloc byte[1]; //doesn't work with zero
    return UnsafeComputeHash(pData, 0, seed);
}

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions