Skip to content
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

Validate the hash salt during object creation #237

Merged
merged 2 commits into from
May 12, 2022

Conversation

geoffreydstewart
Copy link
Member

Description

These changes add validations of the hash salt during object creation, either programmatically or via the Configuration System.

Motivation

These changes fix #233

Copy link
Member

@Craigacp Craigacp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small formatting things mostly. The tests look good, thanks for adding them.

* Used by the OLCUT configuration system, and should not be called by external code.
*/
@Override
public synchronized void postConfig() throws PropertyException{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These postConfigs don't access any other resources under synchronization elsewhere in the class, so we don't need to make them synchronized to avoid static analysis false positives.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, it makes sense to only apply synchronization as needed to safely modify an attribute. I think I may have misunderstood that from a previous discussion. Thanks for clarifying.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the false positive only arises in Trainers as those also access the RNG field under synchronization. In practice as postConfig is always only called either from the constructor, or from OLCUT before the object is published it doesn't actually need synchronization, but the static analysis tools just see a public method and so warn on it.

Core/src/main/java/org/tribuo/hash/HashCodeHasher.java Outdated Show resolved Hide resolved
Core/src/main/java/org/tribuo/hash/ModHashCodeHasher.java Outdated Show resolved Hide resolved
Core/src/main/java/org/tribuo/hash/ModHashCodeHasher.java Outdated Show resolved Hide resolved
Copy link
Member

@Craigacp Craigacp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

@Craigacp Craigacp merged commit 888a9bb into oracle:main May 12, 2022
@geoffreydstewart geoffreydstewart deleted the hasher-validate-salt branch May 12, 2022 21:38
Craigacp pushed a commit that referenced this pull request Oct 25, 2022
* Validate the hash salt during object creation

* Changes to address code review feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hasher.validateSalt(salt) is underutilized
2 participants