Bug Fix+Portability: Improve portability by integral division#136
Merged
jonjoliver merged 1 commit intotrendmicro:masterfrom Oct 8, 2024
Merged
Bug Fix+Portability: Improve portability by integral division#136jonjoliver merged 1 commit intotrendmicro:masterfrom
jonjoliver merged 1 commit intotrendmicro:masterfrom
Conversation
This is a continuation after the commit 755f31e ("3.12.0") which removed the dependency to the float log. Once we find quartile values in TLSH, we perform a float division to get q1/q3 and q2/q3 in percentage (and taken the mod 16) but lacks portability (and has a bug which the committer explains later). If we have a 32-bit divider, a 64-bit / 32-bit division is not that a big cost (it's theoretically one instruction in x86 because the DIV instruction performs a 64-bit / 32-bit division). It also fixes the problem of arithmetic overflow calculating unsigned 32-bit (q1*100) and (q2*100) (if they overflow, the ratio will be an unexpected value).
d8f8506 to
eb6f8c5
Compare
Collaborator
jonjoliver
approved these changes
Sep 19, 2024
Closed
jonjoliver
pushed a commit
to jonjoliver/tlsh
that referenced
this pull request
Oct 8, 2024
<PRE>
08/10/2024
Merge pull request trendmicro#146 - Remove call to sprintf() to avoid warnings
Merge pull request trendmicro#141 - py_ext: use PyVarObject_HEAD instead of PyObject_HEAD_INIT
Merge pull request trendmicro#138 - Build: Define default options only on "default"
Merge pull request trendmicro#136 - Bug Fix+Portability: Improve portability by integral division
</PRE>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a continuation after the commit 755f31e ("3.12.0") which removed the dependency to the float log.
Once we find quartile values in TLSH, we perform a float division to get q1/q3 and q2/q3 in percentage (and taken the mod 16) but lacks portability (and has a bug which the committer explains later).
Note:
q1 <= q2 <= q3.If we have a 32-bit divider, a 64-bit / 32-bit division is not that a big cost (it's theoretically one instruction in x86 because the
DIVinstruction performs a 64-bit / 32-bit division, not 32-bit / 32-bit).It also fixes the problem of arithmetic overflow calculating unsigned 32-bit
(q1*100)and(q2*100)(if they overflow, the ratio will be an unexpected value).Note:
(q1*100)and(q2*100)inu32is clearly a bug (in a normal sense) but I'm not sure whether you consider this a "specification" (as a developer of ssdeep, a fuzzy hash implementation, I acknowledge that we should be very aware of the compatibility). If this is considered a bug, I consider this is a good chance to fix this issue along with improving the portability / reproducibility.Condition (this change may slightly change the hash value):
q2 >= 167773(or:q2 > (1 << 24) / 100) (due to the rough "percentage" metric, it's unlikely to change the hash in practice but I found (q1 or q2, q3) pairs that would change the hash value)Condition (the arithmetic overflow will occur):
q2 >= 42949673(or:q2 > 0xffffffff / 100)