-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a typo that cause inconsistent hash between streaming and stateless way for XXH3 128-bit variant with custom secret and seed 0 #894
Conversation
…d()` when `len <= XXH3_MIDSIZE_MAX`
Hi @hltj , thank you for the report and PR. I also have confirmed your issue and this PR with the following code:
note:
Although this PR fixes the bug, it is a breaking change, technically. So, I think we should think how we can/should mitigate it.
|
Hi @t-mat , thank you so much for confirming, explaining the details as well as the fix/release suggestions. The only I want to clarify that it is not |
@hltj thanks! You're right. I've fixed my comment to prevent further misunderstanding. |
Idea: Since secretAndSeed is the only thing broken afaik, we only need one API to wrap.
// do the namespace and stuff
XXH_DEPRECATED void XXH3_reset_withSecretandSeed();
void XXH3_reset_withSecretandSeed_new();
// end of code
#define XXH3_reset_withSecretandSeed_old XXH3_reset_withSecretandSeed
#ifndef XXH3_OLD_RESET_WITH_SECRET_AND_SEED
# define XXH3_reset_withSecretandSeed XXH3_reset_withSecretandSeed_new
#endif We have used opt-in macros when we did the internal API rename. enum XXH3_stateType {
XXH3_STATE_TYPE_SECRET,
XXH3_STATE_TYPE_SEED,
XXH3_STATE_TYPE_OLD_SECRET_AND_SEED
}; Then in if (state->stateType == XXH3_STATE_TYPE_SEED
|| XXH_unlikely(state->stateType == XXH3_STATE_TYPE_OLD_SECRET_AND_SEED && state->seed != 0)
) And in Make sure we make this very clear in documentation and comments. This way, apps compiled against libxxhash.so won't change since they will use the old symbol, and defining that macro would make theoretical "old apps" that expect the broken hash values for some reason work. |
Coming back on this topic, it looks to me that this is a pretty clear case of detecting and fixing a bug.
So deviating from this contract is a bug, clear and simple. Beyond fixing the bug, what matters is to build an ability to detect such bug in the future, which this PR also provides. So, as far as this PR is concerned, I think it's good to go. The next question is probably: does this fix deserves a new release ? or even an urgent release ? Well, I believe that the entry point
Given this pretty huge list of pre-conditions, I don't anticipate any real-world impact. That being said, this bug definitely deserves a mention on the release page. |
As a side note:
I was testing this capability, That's because, even though these tools use almost the same code, We may benefit from having a single source of truth for the common parts of the code base, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @hltj , that's a great investigation and great fix !
A [bug][] was found in the implementation of `XXH3_128bits_withSecretandSeed`. It has been fixed but not yet released, so we are bumping to the current development version. [bug]: Cyan4973/xxHash#894
A [bug][] was found in the implementation of `XXH3_128bits_withSecretandSeed`. It has been fixed but not yet released, so we are bumping to the current development version. [bug]: Cyan4973/xxHash#894
I found that the streaming way returns different hash from
XXH3_128bits_withSecretandSeed()
with seed0
and a custom secret (notXXH3_kSecret
) when the input length not greater thanXXH3_MIDSIZE_MAX
, while the 64-bit variant works fine.I read the code and felt that there may be a typo that if there is also
if (state->useSeed)
inXXH3_128bits_digest()
, it will be fine too.I also added the test cases for that
_withSecretandSeed
is the same as_withSeed()
whenlen <= XXH3_MIDSIZE_MAX
for both 64-bit and 128-bit variant.