xxhash.h: add defensive NULL checks across state and utility APIs #1158

Open
filtede98 wants to merge 1 commit from filtede98/fix-null-guards into dev
filtede98 commented 2026-10-02 09:19:49 -05:00 (Migrated from github.com)

This patch adds defensive NULL checks to state management and utility functions across XXH32, XXH64, XXH3, and XXH128:

  • XXH32_freeState, XXH64_freeState, XXH3_freeState: return XXH_OK safely when passed a NULL state pointer.
  • XXH32_copyState, XXH64_copyState, XXH3_copyState: no-op if destination or source pointer is NULL.
  • XXH32_reset, XXH64_reset, XXH3_64bits_reset: validate non-NULL state pointer, returning XXH_ERROR on NULL.
  • XXH32_update, XXH64_update, XXH3_update: return XXH_ERROR on NULL state or non-empty NULL input (preserving empty input handling len == 0 -> XXH_OK).
  • XXH3_64bits_reset_withSecret: validate secret != NULL and secretSize >= XXH3_SECRET_SIZE_MIN before calling XXH3_reset_internal (fixing check order).
  • XXH32_digest, XXH64_digest, XXH3_64bits_digest, XXH3_128bits_digest: safely return 0/zero-hash on NULL state.
  • XXH32_canonicalFromHash, XXH64_canonicalFromHash, XXH128_canonicalFromHash: guard against NULL destination buffer.
  • XXH32_hashFromCanonical, XXH64_hashFromCanonical, XXH128_hashFromCanonical: guard against NULL source buffer.
  • XXH128_cmp: return 0 if both are NULL, or sort NULL before non-NULL.
  • XXH3_generateSecret_fromSeed: guard against NULL secretBuffer.
This patch adds defensive NULL checks to state management and utility functions across XXH32, XXH64, XXH3, and XXH128: - XXH32_freeState, XXH64_freeState, XXH3_freeState: return XXH_OK safely when passed a NULL state pointer. - XXH32_copyState, XXH64_copyState, XXH3_copyState: no-op if destination or source pointer is NULL. - XXH32_reset, XXH64_reset, XXH3_64bits_reset: validate non-NULL state pointer, returning XXH_ERROR on NULL. - XXH32_update, XXH64_update, XXH3_update: return XXH_ERROR on NULL state or non-empty NULL input (preserving empty input handling len == 0 -> XXH_OK). - XXH3_64bits_reset_withSecret: validate secret != NULL and secretSize >= XXH3_SECRET_SIZE_MIN before calling XXH3_reset_internal (fixing check order). - XXH32_digest, XXH64_digest, XXH3_64bits_digest, XXH3_128bits_digest: safely return 0/zero-hash on NULL state. - XXH32_canonicalFromHash, XXH64_canonicalFromHash, XXH128_canonicalFromHash: guard against NULL destination buffer. - XXH32_hashFromCanonical, XXH64_hashFromCanonical, XXH128_hashFromCanonical: guard against NULL source buffer. - XXH128_cmp: return 0 if both are NULL, or sort NULL before non-NULL. - XXH3_generateSecret_fromSeed: guard against NULL secretBuffer.
This pull request is broken due to missing fork information.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'filtede98/fix-null-guards:filtede98/fix-null-guards'
git switch 'filtede98/fix-null-guards'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'dev'
git merge --no-ff 'filtede98/fix-null-guards'
git switch 'filtede98/fix-null-guards'
git rebase 'dev'
git switch 'dev'
git merge --ff-only 'filtede98/fix-null-guards'
git switch 'filtede98/fix-null-guards'
git rebase 'dev'
git switch 'dev'
git merge --no-ff 'filtede98/fix-null-guards'
git switch 'dev'
git merge --squash 'filtede98/fix-null-guards'
git switch 'dev'
git merge --ff-only 'filtede98/fix-null-guards'
git switch 'dev'
git merge 'filtede98/fix-null-guards'
git push origin 'dev'
Sign in to join this conversation.
No description provided.